Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
AndiovisualRecord
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yu_Tung
AndiovisualRecord
Commits
a8f0d730
Commit
a8f0d730
authored
Jul 07, 2020
by
Yu_Tung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增詢問是否更改檔名
parent
18cb5e19
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
153 additions
and
20 deletions
+153
-20
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+2
-0
BaseActivity.java
...java/com/example/audiovisualrecord/base/BaseActivity.java
+19
-0
BaseView.java
...ain/java/com/example/audiovisualrecord/base/BaseView.java
+1
-0
MainActivity.java
...a/com/example/audiovisualrecord/ui/main/MainActivity.java
+107
-20
MainContract.java
...a/com/example/audiovisualrecord/ui/main/MainContract.java
+5
-0
dialog_changefilename.xml
app/src/main/res/layout/dialog_changefilename.xml
+17
-0
login.xml
app/src/main/res/layout/login.xml
+2
-0
No files found.
app/src/main/AndroidManifest.xml
View file @
a8f0d730
...
...
@@ -13,6 +13,8 @@
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.ACCESS_NETWORK_STATE"
/>
<application
android:allowBackup=
"true"
android:icon=
"@mipmap/audiovisualrecord"
...
...
app/src/main/java/com/example/audiovisualrecord/base/BaseActivity.java
View file @
a8f0d730
...
...
@@ -13,6 +13,8 @@ import android.os.Bundle;
import
android.os.Environment
;
import
android.provider.DocumentsContract
;
import
android.provider.MediaStore
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.widget.Toast
;
import
androidx.annotation.Nullable
;
...
...
@@ -21,6 +23,8 @@ import androidx.annotation.StringRes;
import
androidx.appcompat.app.AppCompatActivity
;
import
com.example.audiovisualrecord.R
;
import
com.example.audiovisualrecord.ui.main.MainActivity
;
import
com.example.audiovisualrecord.utils.ToastCreator
;
import
java.text.SimpleDateFormat
;
...
...
@@ -122,6 +126,21 @@ public abstract class BaseActivity extends AppCompatActivity implements BaseView
dialog
.
show
();
}
// @Override
// public void showChangeFileNameDialog(String title, String text, DialogInterface.OnClickListener onClickListener_1, DialogInterface.OnClickListener onClickListener_2) {
// LayoutInflater inflater =LayoutInflater.from(this);
// final View v = inflater.inflate(R.layout.dialog_changefilename,null);
// new AlertDialog.Builder(this)
// .setTitle(title)
// .setView(v)
// .setCancelable(false)
// .setPositiveButton(android.R.string.yes,null)
// .setNegativeButton("no",null)
// .create()
// .show();
//
// }
@Override
public
void
showSelectDialog
(
String
text
,
DialogInterface
.
OnClickListener
onClickListener
)
{
new
AlertDialog
.
Builder
(
this
)
...
...
app/src/main/java/com/example/audiovisualrecord/base/BaseView.java
View file @
a8f0d730
...
...
@@ -26,6 +26,7 @@ public interface BaseView {
void
showDialogCaveatMessage
(
String
title
,
String
message
);
void
showDatePickerDialog
(
DatePickerDialog
.
OnDateSetListener
onDateSetListener
);
void
showSelectDialog
(
String
text
,
DialogInterface
.
OnClickListener
onClickListener
);
// void showChangeFileNameDialog(String title,String text,DialogInterface.OnClickListener onClickListener_1,DialogInterface.OnClickListener onClickListener_2);
String
getResourceString
(
@StringRes
int
text
);
String
getTodayTime
();
...
...
app/src/main/java/com/example/audiovisualrecord/ui/main/MainActivity.java
View file @
a8f0d730
...
...
@@ -5,6 +5,7 @@ import androidx.annotation.RequiresApi;
import
androidx.core.content.FileProvider
;
import
androidx.core.os.EnvironmentCompat
;
import
android.app.AlertDialog
;
import
android.content.ContentValues
;
import
android.content.Context
;
import
android.content.DialogInterface
;
...
...
@@ -17,12 +18,15 @@ import android.net.Uri;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Environment
;
import
android.
provider.DocumentsContract
;
import
android.
os.Handler
;
import
android.provider.MediaStore
;
import
android.util.Log
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.EditText
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.example.audiovisualrecord.FileUtil
;
import
com.example.audiovisualrecord.MagicFileChooser
;
...
...
@@ -40,7 +44,6 @@ import org.json.JSONException;
import
org.json.JSONObject
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.text.SimpleDateFormat
;
...
...
@@ -92,7 +95,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
private
boolean
isAndroidQ
=
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
Q
;
Bundle
bag
;
String
token
,
imageFilePath
;
String
token
;
int
countFile
=
0
;
private
TextView
tvCompany
,
tvFactory
,
tvClass
,
tvUnit
,
tvShootType
;
...
...
@@ -102,11 +105,16 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
private
ChooseDeviceItemData
mChooseDeviceItemData
;
private
ArrayList
<
String
>
dialogString
=
new
ArrayList
<>();
private
String
changeFileName
=
""
;
private
List
<
String
>
filepath
=
new
ArrayList
<>();
private
List
<
String
>
filename
=
new
ArrayList
<>();
String
sidData
=
""
;
// String imageFilePhth;
// String videoFilePath;
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
...
...
@@ -119,6 +127,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
mMainData
=
new
MainData
();
mChooseDeviceItemData
=
new
ChooseDeviceItemData
();
createSegVideoFolder
();
}
//創建分割後影片資料夾
...
...
@@ -158,6 +167,8 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
textShootType
=
findViewById
(
R
.
id
.
text_shoottype
);
textFactory
=
findViewById
(
R
.
id
.
text_factory
);
textClass
=
findViewById
(
R
.
id
.
text_class
);
}
private
void
pickImageFromGallery
()
{
...
...
@@ -239,13 +250,14 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
* @return void
*/
public
void
SavaImage
(
Bitmap
bitmap
,
String
path
)
{
File
file
=
new
File
(
path
);
Intent
intent
=
new
Intent
(
Intent
.
ACTION_MEDIA_SCANNER_SCAN_FILE
);
Uri
uri
=
Uri
.
fromFile
(
file
);
intent
.
setData
(
uri
);
this
.
sendBroadcast
(
intent
);
FileOutputStream
fileOutputStream
=
null
;
String
f
ilePhth
;
String
imageF
ilePhth
;
String
fileName
;
//文件夹不存在,则创建它
if
(!
file
.
exists
())
{
...
...
@@ -256,22 +268,24 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyyMMdd_HHmmss"
);
String
formattedDate
=
df
.
format
(
c
);
filePhth
=
path
+
"/IMG_"
+
formattedDate
+
".jpg"
;
fileName
=
System
.
currentTimeMillis
()
+
""
;
Log
.
e
(
"filepath"
,
filePhth
);
File
file1
=
new
File
(
filePhth
);
fileName
=
"IMG_"
+
formattedDate
+
".jpg"
;
imageFilePhth
=
path
+
"/"
+
fileName
;
// fileName = System.currentTimeMillis() + "";
Log
.
e
(
"filepath"
,
imageFilePhth
);
File
file1
=
new
File
(
imageFilePhth
);
fileOutputStream
=
new
FileOutputStream
(
file1
.
getPath
());
bitmap
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
100
,
fileOutputStream
);
fileOutputStream
.
close
();
//图片路径
// MediaStore.Images.Media.insertImage(context.getContentResolver(),
//
f
ilePhth,fileName , null);
//
imageF
ilePhth,fileName , null);
//多存一張照片
// MediaStore.Images.Media.insertImage(this.getContentResolver(), bitmap, "", "");
this
.
sendBroadcast
(
new
Intent
(
Intent
.
ACTION_MEDIA_SCANNER_SCAN_FILE
,
Uri
.
parse
(
"file://"
+
file1
.
getAbsolutePath
())));
Log
.
d
(
"aaa"
,
file1
.
getAbsolutePath
()
+
"-----"
+
path
);
//要改掉下面那行
// this.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file1.getAbsolutePath())));
changeFileNameCheckDialog
(
imageFilePhth
,
fileName
);
// context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://"+ Environment.getExternalStorageDirectory())));
}
catch
(
Exception
e
)
{
// ToastUtil.showToast("保存失败");
...
...
@@ -323,16 +337,16 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
if
(
requestCode
==
REQUEST_VIDEO_CAPTURE
&&
resultCode
==
RESULT_OK
)
{
//影片的uri
String
videoFilePath
;
Uri
videoUri
=
data
.
getData
();
Date
c
=
Calendar
.
getInstance
(
Locale
.
TAIWAN
).
getTime
();
SimpleDateFormat
df
=
new
SimpleDateFormat
(
"yyyyMMdd_HH_mm_ss"
);
String
formattedDate
=
df
.
format
(
c
);
try
{
DocumentsContract
.
renameDocument
(
getContentResolver
(),
videoUri
,
formattedDate
+
".mp4"
);
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
videoFilePath
=
MagicFileChooser
.
getAbsolutePathFromUri
(
this
,
videoUri
);
File
file
=
new
File
(
videoFilePath
);
String
name
=
(
file
.
getName
());
changeFileNameCheckDialog
(
videoFilePath
,
name
);
}
if
(
requestCode
==
PICK_IMAGE_FROM_GALLERY_REQUEST_CODE
&&
resultCode
==
RESULT_OK
)
{
...
...
@@ -668,6 +682,7 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
mChooseDeviceItemData
.
setFactoryAreaName
(
mMainData
.
getmPZDataList
().
get
(
which
).
getmPZNM
());
mChooseDeviceItemData
.
setFactoryAreaId
(
mMainData
.
getmPZDataList
().
get
(
which
).
getmPZ
());
}
};
private
DialogInterface
.
OnClickListener
onFactoryClassDialogItemClick
=
new
DialogInterface
.
OnClickListener
()
{
...
...
@@ -710,4 +725,76 @@ public class MainActivity extends BaseActivity implements MainContract.View, Vie
}
@Override
public
void
changeFileNameCheckDialog
(
final
String
path
,
final
String
name
)
{
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
this
);
//取得自訂版面
LayoutInflater
inflater
=
LayoutInflater
.
from
(
MainActivity
.
this
);
final
View
v
=
inflater
.
inflate
(
R
.
layout
.
dialog_changefilename
,
null
);
builder
.
setTitle
(
"請問要將檔名修改成:"
);
builder
.
setView
(
v
);
builder
.
setCancelable
(
false
);
builder
.
setPositiveButton
(
"確定"
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
EditText
editChangeName
=
v
.
findViewById
(
R
.
id
.
etChangeName
);
changeFileName
=
editChangeName
.
getText
().
toString
();
// Log.e("euu",changeFileName);
if
(
changeFileName
.
length
()
<=
0
){
Toast
.
makeText
(
MainActivity
.
this
,
"請輸入要更改的檔名"
,
Toast
.
LENGTH_SHORT
).
show
();
changeFileNameCheckDialog
(
path
,
name
);
}
else
if
(
changeFileName
.
length
()>
0
){
updateChangeFileName
(
changeFileName
,
path
,
name
);
}
}
}).
setNegativeButton
(
"取消"
,
new
DialogInterface
.
OnClickListener
()
{
@Override
public
void
onClick
(
DialogInterface
dialog
,
int
which
)
{
//廣播圖片or影片
updateMedia
(
path
,
MainActivity
.
this
);
}
});
builder
.
create
();
builder
.
show
();
}
private
void
updateChangeFileName
(
String
changeFileName
,
final
String
path
,
String
originFileName
)
{
if
(
originFileName
.
contains
(
".jpg"
)){
Log
.
e
(
"type"
,
"jpg"
);
File
newFile
=
new
File
(
path
.
replace
(
originFileName
,
changeFileName
)+
".jpg"
);
File
originFile
=
new
File
(
path
);
originFile
.
renameTo
(
newFile
);
updateMedia
(
newFile
.
getAbsolutePath
(),
this
);
}
else
if
(
originFileName
.
contains
(
".mp4"
)){
Log
.
e
(
"type"
,
"mp4"
);
File
newFile
=
new
File
(
path
.
replace
(
originFileName
,
changeFileName
)+
".mp4"
);
File
originFile
=
new
File
(
path
);
originFile
.
renameTo
(
newFile
);
updateMedia
(
newFile
.
getAbsolutePath
(),
this
);
//跑太快畫面來不及更新
showProgressDialog
(
"影片改名中"
);
showProgressDialog
(
"影片改名中"
);
showProgressDialog
(
"影片改名中"
);
showProgressDialog
(
"影片改名中"
);
showProgressDialog
(
"影片改名中"
);
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
Thread
.
sleep
(
3000
);
updateMedia
(
new
File
(
path
).
getAbsolutePath
(),
MainActivity
.
this
);
//把舊檔案更新掉,不然媒體庫會有一個額外且不能用的檔案
dismissProgressDialog
();
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
Log
.
e
(
"error"
,
e
.
getMessage
());
}
}
}).
start
();
// updateMedia(new File(path).getAbsolutePath(),this); //把舊檔案更新掉,不然媒體庫會有一個額外且不能用的檔案
}
}
}
app/src/main/java/com/example/audiovisualrecord/ui/main/MainContract.java
View file @
a8f0d730
package
com
.
example
.
audiovisualrecord
.
ui
.
main
;
import
android.content.Context
;
import
com.example.audiovisualrecord.base.BaseView
;
import
com.example.audiovisualrecord.utils.api.apidata.searchco.COResponse
;
...
...
@@ -20,6 +22,8 @@ public interface MainContract {
void
setEQKDData
(
List
<
SHIFTResponse
>
adapterData
);
void
setTYPEData
(
List
<
TYPEResponse
>
adapterData
);
void
onUploadFile
(
ArrayList
<
String
>
uriList
,
String
type
,
String
sid
);
void
changeFileNameCheckDialog
(
String
path
,
String
name
);
}
interface
Presenter
<
V
extends
MainContract
.
View
>
{
...
...
@@ -33,5 +37,6 @@ public interface MainContract {
void
onLogoutSid
(
String
sid
);
String
onJudgmentPath
(
String
pathCompany
,
String
pathFactoryArea
,
String
pathFactoryClass
,
String
pathClass
,
String
pathShootType
);
}
}
app/src/main/res/layout/dialog_changefilename.xml
0 → 100644
View file @
a8f0d730
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:orientation=
"vertical"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
>
<EditText
android:id=
"@+id/etChangeName"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"16dp"
android:layout_marginLeft=
"4dp"
android:layout_marginRight=
"4dp"
android:layout_marginBottom=
"4dp"
android:hint=
"請輸入要更改的檔名"
/>
</LinearLayout>
\ No newline at end of file
app/src/main/res/layout/login.xml
View file @
a8f0d730
...
...
@@ -49,6 +49,7 @@
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@id/guide_line_horizontal_45"
android:paddingLeft=
"100dp"
/>
<!-- android:text="N000158385"-->
<EditText
android:id=
"@+id/edit_password"
...
...
@@ -66,6 +67,7 @@
app:layout_constraintHeight_percent=
"0.08"
app:layout_constraintTop_toBottomOf=
"@id/guide_line_horizontal_56"
android:paddingLeft=
"100dp"
/>
<!-- android:text="781122222"-->
<Button
android:id=
"@+id/btn_login"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment