一切的开始
@@ -0,0 +1,27 @@
|
||||
package com.fatapp.textcut;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumented test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
|
||||
assertEquals("com.fatapp.textcut", appContext.getPackageName());
|
||||
}
|
||||
}
|
||||
29
app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.fatapp.textcut">
|
||||
<!--读取SDCard数据权限-->
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
|
||||
<!-- 向SDCard写入数据权限 -->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/appName"
|
||||
android:roundIcon="@drawable/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/appName"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
28
app/src/main/java/com/fatapp/textcut/Cut.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.fatapp.textcut;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
class Cut {
|
||||
static ArrayList<String> cutText(String text, int number) {
|
||||
|
||||
ArrayList<String> output = new ArrayList<>();
|
||||
int totalNumber = text.length() - 1;
|
||||
|
||||
|
||||
if (totalNumber % number == 0) {
|
||||
int textNumber = (int) Math.floor((double) totalNumber / (double) number);
|
||||
for (int n = 0; n <= number - 1; n++) {
|
||||
output.add(text.substring(n * textNumber, n * textNumber + textNumber));
|
||||
}
|
||||
} else {
|
||||
int cutNumber = number - 1;
|
||||
int textNumber = (int) Math.floor((double) totalNumber / (double) number);
|
||||
for (int n = 0; n <= cutNumber - 1; n++) {
|
||||
output.add(text.substring(n * textNumber, n * textNumber + textNumber));
|
||||
}
|
||||
output.add(text.substring(cutNumber * textNumber));
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
157
app/src/main/java/com/fatapp/textcut/GetFile.java
Normal file
@@ -0,0 +1,157 @@
|
||||
package com.fatapp.textcut;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
public class GetFile {
|
||||
|
||||
public static String getFileUri(Context context, Uri uri) {
|
||||
String path;
|
||||
if ("file".equalsIgnoreCase(uri.getScheme())) {//使用第三方应用打开
|
||||
path = uri.getPath();
|
||||
}
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {//4.4以后
|
||||
path = getPath(context, uri);
|
||||
} else {//4.4以下下系统调用方法
|
||||
path = getRealPathFromURI(context, uri);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
public static String getRealPathFromURI(Context context, Uri contentUri) {
|
||||
String res = null;
|
||||
String[] proj = {MediaStore.Images.Media.DATA};
|
||||
Cursor cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
|
||||
if (null != cursor && cursor.moveToFirst()) {
|
||||
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
||||
res = cursor.getString(column_index);
|
||||
cursor.close();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 专为Android4.4设计的从Uri获取文件绝对路径,以前的方法已不好使
|
||||
*/
|
||||
@SuppressLint("NewApi")
|
||||
public static String getPath(final Context context, final Uri uri) {
|
||||
|
||||
final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
||||
|
||||
// DocumentProvider
|
||||
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
|
||||
// ExternalStorageProvider
|
||||
if (isExternalStorageDocument(uri)) {
|
||||
final String docId = DocumentsContract.getDocumentId(uri);
|
||||
final String[] split = docId.split(":");
|
||||
final String type = split[0];
|
||||
|
||||
if ("primary".equalsIgnoreCase(type)) {
|
||||
return Environment.getExternalStorageDirectory() + "/" + split[1];
|
||||
}
|
||||
}
|
||||
// DownloadsProvider
|
||||
else if (isDownloadsDocument(uri)) {
|
||||
|
||||
final String id = DocumentsContract.getDocumentId(uri);
|
||||
final Uri contentUri = ContentUris.withAppendedId(
|
||||
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
|
||||
|
||||
return getDataColumn(context, contentUri, null, null);
|
||||
}
|
||||
// MediaProvider
|
||||
else if (isMediaDocument(uri)) {
|
||||
final String docId = DocumentsContract.getDocumentId(uri);
|
||||
final String[] split = docId.split(":");
|
||||
final String type = split[0];
|
||||
|
||||
Uri contentUri = null;
|
||||
if ("image".equals(type)) {
|
||||
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
||||
} else if ("video".equals(type)) {
|
||||
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
||||
} else if ("audio".equals(type)) {
|
||||
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
||||
}
|
||||
|
||||
final String selection = "_id=?";
|
||||
final String[] selectionArgs = new String[]{split[1]};
|
||||
|
||||
return getDataColumn(context, contentUri, selection, selectionArgs);
|
||||
}
|
||||
}
|
||||
// MediaStore (and general)
|
||||
else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
||||
return getDataColumn(context, uri, null, null);
|
||||
}
|
||||
// File
|
||||
else if ("file".equalsIgnoreCase(uri.getScheme())) {
|
||||
return uri.getPath();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of the data column for this Uri. This is useful for
|
||||
* MediaStore Uris, and other file-based ContentProviders.
|
||||
*
|
||||
* @param context The context.
|
||||
* @param uri The Uri to query.
|
||||
* @param selection (Optional) Filter used in the query.
|
||||
* @param selectionArgs (Optional) Selection arguments used in the query.
|
||||
* @return The value of the _data column, which is typically a file path.
|
||||
*/
|
||||
public static String getDataColumn(Context context, Uri uri, String selection,
|
||||
String[] selectionArgs) {
|
||||
|
||||
Cursor cursor = null;
|
||||
final String column = "_data";
|
||||
final String[] projection = {column};
|
||||
|
||||
try {
|
||||
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
|
||||
null);
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
final int column_index = cursor.getColumnIndexOrThrow(column);
|
||||
return cursor.getString(column_index);
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uri The Uri to check.
|
||||
* @return Whether the Uri authority is ExternalStorageProvider.
|
||||
*/
|
||||
public static boolean isExternalStorageDocument(Uri uri) {
|
||||
return "com.android.externalstorage.documents".equals(uri.getAuthority());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uri The Uri to check.
|
||||
* @return Whether the Uri authority is DownloadsProvider.
|
||||
*/
|
||||
public static boolean isDownloadsDocument(Uri uri) {
|
||||
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uri The Uri to check.
|
||||
* @return Whether the Uri authority is MediaProvider.
|
||||
*/
|
||||
public static boolean isMediaDocument(Uri uri) {
|
||||
return "com.android.providers.media.documents".equals(uri.getAuthority());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
162
app/src/main/java/com/fatapp/textcut/GetText.java
Normal file
@@ -0,0 +1,162 @@
|
||||
package com.fatapp.textcut;
|
||||
|
||||
import org.apache.http.util.ByteArrayBuffer;
|
||||
import org.apache.http.util.EncodingUtils;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.LineNumberReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class GetText {
|
||||
private static int lineNumber;
|
||||
private static int onLine;
|
||||
private static String text;
|
||||
private static Boolean done;
|
||||
|
||||
/**
|
||||
* @返回 TXT文件的所有字符 用String 接收
|
||||
*/
|
||||
public static String GetLog(String path) {
|
||||
String txt;
|
||||
int current;
|
||||
File file = new File(path);
|
||||
ByteArrayBuffer bb = new ByteArrayBuffer(500);
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new FileReader(file));
|
||||
while ((current = reader.read()) != -1) {
|
||||
bb.append(current);
|
||||
}
|
||||
reader.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
txt = EncodingUtils.getString(bb.toByteArray(), "GB2312");
|
||||
return txt;
|
||||
}
|
||||
|
||||
public static BufferedReader convertCodeAndGetText(String str_filepath) {// 转码
|
||||
|
||||
File file = new File(str_filepath);
|
||||
BufferedReader reader = null;
|
||||
|
||||
|
||||
try {
|
||||
LineNumberReader lnr = new LineNumberReader(new FileReader(file));
|
||||
lnr.skip(Long.MAX_VALUE);
|
||||
|
||||
// FileReader f_reader = new FileReader(file);
|
||||
// BufferedReader reader = new BufferedReader(f_reader);
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
BufferedInputStream in = new BufferedInputStream(fis);
|
||||
in.mark(4);
|
||||
byte[] first3bytes = new byte[3];
|
||||
in.read(first3bytes);//找到文档的前三个字节并自动判断文档类型。
|
||||
in.reset();
|
||||
if (first3bytes[0] == (byte) 0xEF && first3bytes[1] == (byte) 0xBB
|
||||
&& first3bytes[2] == (byte) 0xBF) {// utf-8
|
||||
|
||||
reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||
|
||||
} else if (first3bytes[0] == (byte) 0xFF
|
||||
&& first3bytes[1] == (byte) 0xFE) {
|
||||
|
||||
reader = new BufferedReader(
|
||||
new InputStreamReader(in, "unicode"));
|
||||
} else if (first3bytes[0] == (byte) 0xFE
|
||||
&& first3bytes[1] == (byte) 0xFF) {
|
||||
|
||||
reader = new BufferedReader(new InputStreamReader(in,
|
||||
StandardCharsets.UTF_16BE));
|
||||
} else if (first3bytes[0] == (byte) 0xFF
|
||||
&& first3bytes[1] == (byte) 0xFF) {
|
||||
|
||||
reader = new BufferedReader(new InputStreamReader(in,
|
||||
StandardCharsets.UTF_16LE));
|
||||
} else {
|
||||
|
||||
reader = new BufferedReader(new InputStreamReader(in, "GBK"));
|
||||
}
|
||||
|
||||
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return reader;
|
||||
}
|
||||
|
||||
|
||||
public static int getFileLineNumber(BufferedReader reader) throws IOException {
|
||||
lineNumber = 0;
|
||||
//读入文件数据
|
||||
LineNumberReader lnr = new LineNumberReader(reader);
|
||||
//开始一个字符一个字符的跳过 一直到最后一个字符。读取完成
|
||||
lnr.skip(Long.MAX_VALUE);
|
||||
//有一个换行符
|
||||
lineNumber = lnr.getLineNumber() + 1;
|
||||
lnr.close();
|
||||
return lineNumber;
|
||||
|
||||
}
|
||||
|
||||
public static String getText(BufferedReader reader) {
|
||||
text = "";
|
||||
onLine = 1;
|
||||
|
||||
try {
|
||||
String str = reader.readLine();
|
||||
while (str != null) {
|
||||
onLine++;
|
||||
text = text + str + "\n";
|
||||
str = reader.readLine();
|
||||
}
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
done = true;
|
||||
return text;
|
||||
}
|
||||
|
||||
public static int getLineNumber() {
|
||||
return lineNumber;
|
||||
}
|
||||
|
||||
private static void setLineNumber(int n) {
|
||||
lineNumber = n;
|
||||
}
|
||||
|
||||
public static int getOnLine() {
|
||||
return onLine;
|
||||
}
|
||||
|
||||
public static void setOnLine(int n) {
|
||||
onLine = n;
|
||||
}
|
||||
|
||||
public static String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public static void setText(String t) {
|
||||
text = t;
|
||||
}
|
||||
|
||||
public static Boolean getDone() {
|
||||
return done;
|
||||
}
|
||||
|
||||
public static void setDone(Boolean b) {
|
||||
done = b;
|
||||
}
|
||||
}
|
||||
417
app/src/main/java/com/fatapp/textcut/MainActivity.java
Normal file
@@ -0,0 +1,417 @@
|
||||
package com.fatapp.textcut;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import cn.carbswang.android.numberpickerview.library.NumberPickerView;
|
||||
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
final int REQUEST_CODE_CHOOSE_FILE = 0;
|
||||
|
||||
private boolean loading = false;
|
||||
private String filePath;
|
||||
|
||||
private Dialog mDialog;
|
||||
|
||||
private int choseNumber = 0;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
getPermissins();
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
FloatingActionButton fab = findViewById(R.id.fab);
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||
intent.setType("text/plain");
|
||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||
startActivityForResult(intent, REQUEST_CODE_CHOOSE_FILE);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
findViewById(R.id.transform).setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
//显示按下时的背景图片
|
||||
v.setBackgroundResource(R.drawable.button_roud_shape_click);
|
||||
} else if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
//显示抬起时的背景图片
|
||||
v.setBackgroundResource(R.drawable.button_round_shape);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
findViewById(R.id.transform).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showDialog();
|
||||
}
|
||||
});
|
||||
|
||||
//定义一个setting记录APP是几次启动
|
||||
SharedPreferences setting = getSharedPreferences("com.fatapp.textcut", 0);
|
||||
boolean user_first = setting.getBoolean("FIRST", true);
|
||||
if (user_first) {// 第一次则跳转到欢迎页面
|
||||
setting.edit().putBoolean("FIRST", false).apply();
|
||||
}
|
||||
}
|
||||
|
||||
private long mExitTime;
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (loading) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK)
|
||||
Toast.makeText(this, R.string.cannotBack, Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
} else {
|
||||
//与上次点击返回键时刻作差
|
||||
if ((System.currentTimeMillis() - mExitTime) > 2000) {
|
||||
//大于2000ms则认为是误操作,使用Toast进行提示
|
||||
Toast.makeText(this, R.string.exitWarn, Toast.LENGTH_SHORT).show();
|
||||
//并记录下本次点击“返回键”的时刻,以便下次进行判断
|
||||
mExitTime = System.currentTimeMillis();
|
||||
} else {
|
||||
//小于2000ms则认为是用户确实希望退出程序-调用System.exit()方法进行退出
|
||||
System.exit(0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}//屏蔽返回键
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (id == R.id.action_settings) {
|
||||
System.exit(0);
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
String path;
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_CHOOSE_FILE:
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Uri uri;
|
||||
uri = data.getData();
|
||||
|
||||
if ("file".equalsIgnoreCase(uri.getScheme())) {//使用第三方应用打开
|
||||
path = uri.getPath();
|
||||
}
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {//4.4以后
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
path = uri.getPath();
|
||||
Log.println(Log.ERROR, "Path ", path);
|
||||
} else {
|
||||
path = GetFile.getPath(this, uri);
|
||||
}
|
||||
} else {//4.4以下下系统调用方法
|
||||
path = GetFile.getRealPathFromURI(getBaseContext(), uri);
|
||||
}
|
||||
|
||||
|
||||
filePath = path;
|
||||
|
||||
File text = new File(filePath);
|
||||
if (text.isFile() | text.exists()) {
|
||||
try {
|
||||
int n = GetText.getFileLineNumber(GetText.convertCodeAndGetText(text.getAbsolutePath()));
|
||||
Toast.makeText(this, getString(R.string.totalLine, Integer.toString(n)), Toast.LENGTH_SHORT).show();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
final File txt = new File(filePath);
|
||||
if (txt.isFile() | txt.exists()) {
|
||||
GetText.setDone(false);
|
||||
MainActivity.this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
|
||||
loading = true;
|
||||
findViewById(R.id.loadingView).setVisibility(View.VISIBLE);
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
//在这里可以进行UI操作
|
||||
do {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
float percent = (float) GetText.getOnLine() / GetText.getLineNumber() * 100;
|
||||
TextView loadingText = findViewById(R.id.loadingText);
|
||||
loadingText.setText(getString(R.string.transCoding, Integer.toString((int) percent), Integer.toString(GetText.getOnLine()), Integer.toString(GetText.getLineNumber())));
|
||||
}
|
||||
});
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} while (!GetText.getDone());
|
||||
}
|
||||
}).start();
|
||||
new Thread(new Runnable() {
|
||||
public void run() {
|
||||
GetText.getText(GetText.convertCodeAndGetText(txt.getAbsolutePath()));
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
TextView o = findViewById(R.id.originalTextView);
|
||||
o.setText(GetText.getText());
|
||||
findViewById(R.id.loadingView).setVisibility(View.GONE);
|
||||
MainActivity.this.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
|
||||
loading = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
PermissionUtils.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
private void getPermissins() {
|
||||
requestPermissins(new PermissionUtils.OnPermissionListener() {
|
||||
@Override
|
||||
public void onPermissionGranted() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionDenied(String[] deniedPermissions) {
|
||||
Toast.makeText(MainActivity.this, R.string.permissionDenied, Toast.LENGTH_SHORT).show();
|
||||
getPermissins();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void requestPermissins(PermissionUtils.OnPermissionListener mOnPermissionListener) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
mOnPermissionListener.onPermissionGranted();
|
||||
return;
|
||||
}
|
||||
String[] permissions = {"android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE"};
|
||||
PermissionUtils.requestPermissions(this, 0
|
||||
, permissions, mOnPermissionListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* 显示弹出框
|
||||
*/
|
||||
private void showDialog() {
|
||||
if (mDialog == null) {
|
||||
initDialog();
|
||||
}
|
||||
mDialog.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化分享弹出框
|
||||
*/
|
||||
private void initDialog() {
|
||||
mDialog = new Dialog(this, R.style.ActionSheetDialogStyle);
|
||||
mDialog.setCanceledOnTouchOutside(true); //手指触碰到外界取消
|
||||
mDialog.setCancelable(true); //可取消 为true
|
||||
Window window = mDialog.getWindow(); // 得到dialog的窗体
|
||||
window.setGravity(Gravity.BOTTOM);
|
||||
window.setWindowAnimations(R.style.ActionSheetDialogAnimation);
|
||||
|
||||
View view = View.inflate(this, R.layout.dialog_layout, null); //获取布局视图
|
||||
final NumberPickerView picker = view.findViewById(R.id.picker);
|
||||
ArrayList<String> displayValuesList = new ArrayList<>();
|
||||
for (int i = 2; i <= 100; i++) {
|
||||
displayValuesList.add(Integer.toString(i));
|
||||
}
|
||||
String[] displayValues = new String[displayValuesList.size()];
|
||||
displayValues = displayValuesList.toArray(displayValues);
|
||||
picker.setDisplayedValues(displayValues);
|
||||
picker.setMinValue(2);
|
||||
picker.setMaxValue(100);
|
||||
picker.setValue(2);
|
||||
|
||||
view.findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (mDialog != null && mDialog.isShowing()) {
|
||||
mDialog.dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
view.findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
choseNumber = picker.getValue();
|
||||
|
||||
if (GetText.getText() == null) {
|
||||
Snackbar.make(v, R.string.sourceTextEmpty, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
if (GetText.getText().length() - 1 < choseNumber) {
|
||||
Snackbar.make(v, R.string.cutNumberTooBig, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
ArrayList<String> output = Cut.cutText(GetText.getText(), choseNumber);
|
||||
|
||||
File file = new File(filePath);
|
||||
String fileName = getFileNameNoEx(file.getName());
|
||||
for (int n = 0; n <= output.size() - 1; n++) {
|
||||
int m = n + 1;
|
||||
writeTxtToFile(output.get(n), file.getParent() + "/" + fileName + "/", fileName + "_" + m + ".txt");
|
||||
}
|
||||
|
||||
if (mDialog != null && mDialog.isShowing()) {
|
||||
mDialog.dismiss();
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Snackbar.make(findViewById(R.id.contentView), R.string.save + ": " + file.getParent() + "/" + fileName + "/", Snackbar.LENGTH_LONG).show();
|
||||
// Toast.makeText(getBaseContext(), "已将文本切割成" + choseNumber + "份", Toast.LENGTH_SHORT).show();
|
||||
// Toast.makeText(getBaseContext(), "保存:" + file.getParent() + "/" + fileName + "/", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
window.setContentView(view);
|
||||
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);//设置横向全屏
|
||||
}
|
||||
|
||||
/*
|
||||
* Java文件操作 获取不带扩展名的文件名
|
||||
* */
|
||||
public static String getFileNameNoEx(String filename) {
|
||||
if ((filename != null) && (filename.length() > 0)) {
|
||||
int dot = filename.lastIndexOf('.');
|
||||
if ((dot > -1) && (dot < (filename.length()))) {
|
||||
return filename.substring(0, dot);
|
||||
}
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
// 将字符串写入到文本文件中
|
||||
private void writeTxtToFile(String strcontent, String filePath, String fileName) {
|
||||
//生成文件夹之后,再生成文件,不然会出错
|
||||
makeFilePath(filePath, fileName);
|
||||
|
||||
String strFilePath = filePath + fileName;
|
||||
// 每次写入时,都换行写
|
||||
String strContent = strcontent + "\r\n";
|
||||
try {
|
||||
File file = new File(strFilePath);
|
||||
if (!file.exists()) {
|
||||
Log.d("TestFile", "Create the file:" + strFilePath);
|
||||
file.getParentFile().mkdirs();
|
||||
file.createNewFile();
|
||||
}
|
||||
RandomAccessFile raf = new RandomAccessFile(file, "rwd");
|
||||
raf.seek(file.length());
|
||||
raf.write(strContent.getBytes());
|
||||
raf.close();
|
||||
} catch (Exception e) {
|
||||
Log.e("TestFile", "Error on write File:" + e);
|
||||
}
|
||||
}
|
||||
|
||||
//生成文件
|
||||
|
||||
private File makeFilePath(String filePath, String fileName) {
|
||||
File file = null;
|
||||
makeRootDirectory(filePath);
|
||||
try {
|
||||
file = new File(filePath + fileName);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
file.createNewFile();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
//生成文件夹
|
||||
|
||||
private static void makeRootDirectory(String filePath) {
|
||||
File file = null;
|
||||
try {
|
||||
file = new File(filePath);
|
||||
if (!file.exists()) {
|
||||
file.mkdir();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.i("error:", e + "");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
12
app/src/main/java/com/fatapp/textcut/NumberPicker.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.fatapp.textcut;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
public class NumberPicker extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
}
|
||||
136
app/src/main/java/com/fatapp/textcut/PermissionUtils.java
Normal file
@@ -0,0 +1,136 @@
|
||||
package com.fatapp.textcut;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* desc : 权限相关工具类
|
||||
* </pre>
|
||||
*/
|
||||
public final class PermissionUtils {
|
||||
|
||||
private static int mRequestCode = -1;
|
||||
|
||||
private static OnPermissionListener mOnPermissionListener;
|
||||
|
||||
public interface OnPermissionListener {
|
||||
|
||||
void onPermissionGranted();
|
||||
|
||||
void onPermissionDenied(String[] deniedPermissions);
|
||||
}
|
||||
|
||||
public abstract static class RationaleHandler {
|
||||
private Context context;
|
||||
private int requestCode;
|
||||
private String[] permissions;
|
||||
|
||||
protected abstract void showRationale();
|
||||
|
||||
void showRationale(Context context, int requestCode, String[] permissions) {
|
||||
this.context = context;
|
||||
this.requestCode = requestCode;
|
||||
this.permissions = permissions;
|
||||
showRationale();
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
public void requestPermissionsAgain() {
|
||||
((Activity) context).requestPermissions(permissions, requestCode);
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
public static void requestPermissions(Context context, int requestCode
|
||||
, String[] permissions, OnPermissionListener listener) {
|
||||
requestPermissions(context, requestCode, permissions, listener, null);
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
public static void requestPermissions(Context context, int requestCode
|
||||
, String[] permissions, OnPermissionListener listener, RationaleHandler handler) {
|
||||
if (context instanceof Activity) {
|
||||
mRequestCode = requestCode;
|
||||
mOnPermissionListener = listener;
|
||||
String[] deniedPermissions = getDeniedPermissions(context, permissions);
|
||||
if (deniedPermissions.length > 0) {
|
||||
boolean rationale = shouldShowRequestPermissionRationale(context, deniedPermissions);
|
||||
if (rationale && handler != null) {
|
||||
handler.showRationale(context, requestCode, deniedPermissions);
|
||||
} else {
|
||||
((Activity) context).requestPermissions(deniedPermissions, requestCode);
|
||||
}
|
||||
} else {
|
||||
if (mOnPermissionListener != null)
|
||||
mOnPermissionListener.onPermissionGranted();
|
||||
}
|
||||
} else {
|
||||
throw new RuntimeException("Context must be an Activity");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求权限结果,对应Activity中onRequestPermissionsResult()方法。
|
||||
*/
|
||||
public static void onRequestPermissionsResult(Activity context, int requestCode, String[] permissions, int[]
|
||||
grantResults) {
|
||||
if (mRequestCode != -1 && requestCode == mRequestCode) {
|
||||
if (mOnPermissionListener != null) {
|
||||
String[] deniedPermissions = getDeniedPermissions(context, permissions);
|
||||
if (deniedPermissions.length > 0) {
|
||||
mOnPermissionListener.onPermissionDenied(deniedPermissions);
|
||||
} else {
|
||||
mOnPermissionListener.onPermissionGranted();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求权限中需要授权的权限
|
||||
*/
|
||||
private static String[] getDeniedPermissions(Context context, String[] permissions) {
|
||||
List<String> deniedPermissions = new ArrayList<>();
|
||||
for (String permission : permissions) {
|
||||
if (ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_DENIED) {
|
||||
deniedPermissions.add(permission);
|
||||
}
|
||||
}
|
||||
return deniedPermissions.toArray(new String[deniedPermissions.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否彻底拒绝了某项权限
|
||||
*/
|
||||
public static boolean hasAlwaysDeniedPermission(Context context, String... deniedPermissions) {
|
||||
for (String deniedPermission : deniedPermissions) {
|
||||
if (!shouldShowRequestPermissionRationale(context, deniedPermission)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有权限需要说明提示
|
||||
*/
|
||||
private static boolean shouldShowRequestPermissionRationale(Context context, String... deniedPermissions) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false;
|
||||
boolean rationale;
|
||||
for (String permission : deniedPermissions) {
|
||||
rationale = ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, permission);
|
||||
if (rationale) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
5
app/src/main/res/anim/actionsheet_dialog_in.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<translate xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:duration="200"
|
||||
android:fromYDelta="100%"
|
||||
android:toYDelta="0" />
|
||||
5
app/src/main/res/anim/actionsheet_dialog_out.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<translate xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:duration="200"
|
||||
android:fromYDelta="0"
|
||||
android:toYDelta="100%" />
|
||||
BIN
app/src/main/res/drawable-hdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
app/src/main/res/drawable-hdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
app/src/main/res/drawable-mdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
app/src/main/res/drawable-mdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
app/src/main/res/drawable-xhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 4.1 KiB |
BIN
app/src/main/res/drawable-xhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 7.2 KiB |
BIN
app/src/main/res/drawable-xxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
BIN
app/src/main/res/drawable-xxhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
app/src/main/res/drawable-xxxhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
5
app/src/main/res/drawable/background.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="#ffffff" />
|
||||
<corners android:radius="10dp" />
|
||||
</shape>
|
||||
12
app/src/main/res/drawable/button_roud_shape_click.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval"
|
||||
android:useLevel="false">
|
||||
<solid android:color="@color/mainColorDark" />
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="#FFFFFF" />
|
||||
<size
|
||||
android:width="40dp"
|
||||
android:height="40dp" />
|
||||
</shape>
|
||||
12
app/src/main/res/drawable/button_round_shape.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval"
|
||||
android:useLevel="false">
|
||||
<solid android:color="@color/mainColor" />
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="#FFFFFF" />
|
||||
<size
|
||||
android:width="64dp"
|
||||
android:height="64dp" />
|
||||
</shape>
|
||||
9
app/src/main/res/drawable/ic_add_white_24dp.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="@color/addTab"
|
||||
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
|
||||
</vector>
|
||||
9
app/src/main/res/drawable/ic_content_cut_white_24dp.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FFFFFF"
|
||||
android:pathData="M9.64,7.64c0.23,-0.5 0.36,-1.05 0.36,-1.64 0,-2.21 -1.79,-4 -4,-4S2,3.79 2,6s1.79,4 4,4c0.59,0 1.14,-0.13 1.64,-0.36L10,12l-2.36,2.36C7.14,14.13 6.59,14 6,14c-2.21,0 -4,1.79 -4,4s1.79,4 4,4 4,-1.79 4,-4c0,-0.59 -0.13,-1.14 -0.36,-1.64L12,14l7,7h3v-1L9.64,7.64zM6,8c-1.1,0 -2,-0.89 -2,-2s0.9,-2 2,-2 2,0.89 2,2 -0.9,2 -2,2zM6,20c-1.1,0 -2,-0.89 -2,-2s0.9,-2 2,-2 2,0.89 2,2 -0.9,2 -2,2zM12,12.5c-0.28,0 -0.5,-0.22 -0.5,-0.5s0.22,-0.5 0.5,-0.5 0.5,0.22 0.5,0.5 -0.22,0.5 -0.5,0.5zM19,3l-6,6 2,2 7,-7L22,3z" />
|
||||
</vector>
|
||||
BIN
app/src/main/res/drawable/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 72 KiB |
69
app/src/main/res/layout/activity_main.xml
Normal file
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<include layout="@layout/content_main" />
|
||||
|
||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
app:backgroundTint="?attr/colorPrimary"
|
||||
app:maxImageSize="32dp"
|
||||
app:srcCompat="@drawable/ic_add_white_24dp" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/loadingView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/background"
|
||||
android:visibility="gone">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<com.github.ybq.android.spinkit.SpinKitView
|
||||
android:id="@+id/loadingAnimation"
|
||||
style="@style/SpinKitView.CubeGrid"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_margin="16dp"
|
||||
app:SpinKit_Color="@color/colorAccent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/loadingText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_margin="16dp"
|
||||
android:gravity="center"
|
||||
android:textSize="30sp" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
47
app/src/main/res/layout/content_main.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:context=".MainActivity"
|
||||
tools:showIn="@layout/activity_main">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/contentView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/originalTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="6"
|
||||
android:layout_margin="12dp"
|
||||
android:text="@string/originalTextPreview"
|
||||
android:textIsSelectable="true" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:orientation="horizontal"
|
||||
android:padding="4dp"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="1">
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/transform"
|
||||
style="@style/Widget.AppCompat.ImageButton"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
android:background="@drawable/button_round_shape"
|
||||
app:srcCompat="@drawable/ic_content_cut_white_24dp"
|
||||
android:contentDescription="Transform" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
61
app/src/main/res/layout/dialog_layout.xml
Normal file
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/background"
|
||||
android:layout_height="wrap_content"
|
||||
tools:context=".NumberPicker">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="45dp"
|
||||
android:orientation="horizontal"
|
||||
android:padding="4dp">
|
||||
|
||||
<Button
|
||||
android:id="@+id/close"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#80666666"
|
||||
android:text="@string/cancel" />
|
||||
|
||||
<Space
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/ok"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#80666666"
|
||||
android:text="@string/ok" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:orientation="horizontal"
|
||||
android:padding="10dp">
|
||||
|
||||
<cn.carbswang.android.numberpickerview.library.NumberPickerView
|
||||
android:id="@+id/picker"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="4"
|
||||
android:contentDescription="test_number_picker_view"
|
||||
app:npv_ItemPaddingHorizontal="5dp"
|
||||
app:npv_ItemPaddingVertical="5dp"
|
||||
app:npv_RespondChangeOnDetached="false"
|
||||
app:npv_ShownCount="5"
|
||||
app:npv_TextSizeNormal="16sp"
|
||||
app:npv_TextSizeSelected="20sp"
|
||||
app:npv_WrapSelectorWheel="true" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
11
app/src/main/res/menu/menu_main.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.fatapp.textcut.MainActivity">
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
android:title="@string/actionExit"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
44
app/src/main/res/values-v21/styles.xml
Normal file
@@ -0,0 +1,44 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.NoActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||
|
||||
|
||||
<style name="ActionSheetDialogStyle" parent="@android:style/Theme.Dialog">
|
||||
|
||||
<!-- 背景透明 -->
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
<!-- 浮于Activity之上 -->
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
<!-- 边框 -->
|
||||
<item name="android:windowFrame">@null</item>
|
||||
<!-- Dialog以外的区域模糊效果 -->
|
||||
<item name="android:backgroundDimEnabled">true</item>
|
||||
<!-- 无标题 -->
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<!-- 半透明 -->
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<!-- Dialog进入及退出动画 -->
|
||||
<item name="android:windowAnimationStyle">@style/ActionSheetDialogAnimation</item>
|
||||
</style>
|
||||
<!-- ActionSheet进出动画 -->
|
||||
<style name="ActionSheetDialogAnimation" parent="@android:style/Animation.Dialog">
|
||||
<item name="android:windowEnterAnimation">@anim/actionsheet_dialog_in</item>
|
||||
<item name="android:windowExitAnimation">@anim/actionsheet_dialog_out</item>
|
||||
</style>
|
||||
</resources>
|
||||
12
app/src/main/res/values/colors.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="mainColor">#1bbc9b</color>
|
||||
<color name="mainColorDark">#1bbc9b</color>
|
||||
<color name="colorPrimary">@color/mainColor</color>
|
||||
<color name="colorPrimaryDark">@color/mainColorDark</color>
|
||||
<color name="colorAccent">@color/mainColor</color>
|
||||
<color name="addTab">#FFFFFF</color>
|
||||
<color name="background">#80666666</color>
|
||||
<color name="main_color">@color/mainColor</color>
|
||||
<color name="secondary_color">@color/colorAccent</color>
|
||||
</resources>
|
||||
3
app/src/main/res/values/dimens.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<dimen name="fab_margin">16dp</dimen>
|
||||
</resources>
|
||||
10
app/src/main/res/values/menu/menu_main.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:context="com.fatapp.textcut.MainActivity">
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
android:title="@string/actionExit"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
15
app/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<resources>
|
||||
<string name="appName">Text Cut</string>
|
||||
<string name="actionExit">退出</string>
|
||||
<string name="originalTextPreview">源文本预览</string>
|
||||
<string name="transCoding">转码中 %1$s%%\n(%2$s/%3$s)</string>
|
||||
<string name="totalLine">共%1$s行</string>
|
||||
<string name="cannotBack">无法返回该阶段</string>
|
||||
<string name="exitWarn">再按一次退出程序</string>
|
||||
<string name="permissionDenied">未获取到存储权限,请授权</string>
|
||||
<string name="sourceTextEmpty">源文本为空</string>
|
||||
<string name="cutNumberTooBig">源文本字数必须大于分割数量</string>
|
||||
<string name="save">保存</string>
|
||||
<string name="cancel">取消</string>
|
||||
<string name="ok">确定</string>
|
||||
</resources>
|
||||
44
app/src/main/res/values/styles.xml
Normal file
@@ -0,0 +1,44 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.NoActionBar">
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||
|
||||
|
||||
<style name="ActionSheetDialogStyle" parent="@android:style/Theme.Dialog">
|
||||
|
||||
<!-- 背景透明 -->
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
<!-- 浮于Activity之上 -->
|
||||
<item name="android:windowIsFloating">true</item>
|
||||
<!-- 边框 -->
|
||||
<item name="android:windowFrame">@null</item>
|
||||
<!-- Dialog以外的区域模糊效果 -->
|
||||
<item name="android:backgroundDimEnabled">true</item>
|
||||
<!-- 无标题 -->
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<!-- 半透明 -->
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<!-- Dialog进入及退出动画 -->
|
||||
<item name="android:windowAnimationStyle">@style/ActionSheetDialogAnimation</item>
|
||||
</style>
|
||||
<!-- ActionSheet进出动画 -->
|
||||
<style name="ActionSheetDialogAnimation" parent="@android:style/Animation.Dialog">
|
||||
<item name="android:windowEnterAnimation">@anim/actionsheet_dialog_in</item>
|
||||
<item name="android:windowExitAnimation">@anim/actionsheet_dialog_out</item>
|
||||
</style>
|
||||
</resources>
|
||||
17
app/src/test/java/com/fatapp/textcut/ExampleUnitTest.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.fatapp.textcut;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
public class ExampleUnitTest {
|
||||
@Test
|
||||
public void addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2);
|
||||
}
|
||||
}
|
||||