添加时间戳拷贝与显示的格式设置功能
This commit is contained in:
parent
1062c7d2ee
commit
551b424960
@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Tue May 06 02:08:16 GMT 2025
|
||||
#Tue May 06 02:45:43 GMT 2025
|
||||
stageCount=0
|
||||
libraryProject=
|
||||
baseVersion=15.0
|
||||
publishVersion=15.0.0
|
||||
buildCount=101
|
||||
buildCount=108
|
||||
baseBetaVersion=15.0.1
|
||||
|
@ -2,20 +2,30 @@ package cc.winboll.studio.timestamp;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.LogView;
|
||||
import cc.winboll.studio.timestamp.MainService;
|
||||
import cc.winboll.studio.timestamp.R;
|
||||
import cc.winboll.studio.timestamp.utils.AppConfigsUtil;
|
||||
import cc.winboll.studio.timestamp.utils.TimeStampRemoteViewsUtil;
|
||||
import com.hjq.toast.ToastUtils;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
public static final String TAG = "MainActivity";
|
||||
|
||||
EditText metTimeStampFormatString;
|
||||
TextView mtvTimeStampFormatString;
|
||||
EditText metTimeStampCopyFormatString;
|
||||
TextView mtvTimeStampCopyFormatString;
|
||||
|
||||
LogView mLogView;
|
||||
Switch mswEnableMainService;
|
||||
@ -28,6 +38,16 @@ public class MainActivity extends AppCompatActivity {
|
||||
Toolbar toolbar=(Toolbar)findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
metTimeStampFormatString = findViewById(R.id.et_timestampformatstring);
|
||||
mtvTimeStampFormatString = findViewById(R.id.tv_timestampformatstring);
|
||||
metTimeStampCopyFormatString = findViewById(R.id.et_timestampcopyformatstring);
|
||||
mtvTimeStampCopyFormatString = findViewById(R.id.tv_timestampcopyformatstring);
|
||||
|
||||
metTimeStampFormatString.setText(AppConfigsUtil.getInstance(this).getAppConfigsModel().getTimeStampFormatString());
|
||||
showPreViewResult(metTimeStampFormatString, mtvTimeStampFormatString);
|
||||
metTimeStampCopyFormatString.setText(AppConfigsUtil.getInstance(this).getAppConfigsModel().getTimeStampCopyFormatString());
|
||||
showPreViewResult(metTimeStampCopyFormatString, mtvTimeStampCopyFormatString);
|
||||
|
||||
mswEnableMainService = findViewById(R.id.activitymainSwitch1);
|
||||
mswEnableMainService.setChecked(AppConfigsUtil.getInstance(this).loadAppConfigs().isEnableService());
|
||||
|
||||
@ -46,6 +66,35 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
public void onSetMainServiceStatus(View view) {
|
||||
MainService.setMainServiceStatus(this, mswEnableMainService.isChecked());
|
||||
}
|
||||
|
||||
public void onSaveFormatString(View view) {
|
||||
if(showPreViewResult(metTimeStampFormatString, mtvTimeStampFormatString)) {
|
||||
AppConfigsUtil.getInstance(this).getAppConfigsModel().setTimeStampFormatString(metTimeStampFormatString.getText().toString());
|
||||
AppConfigsUtil.getInstance(this).saveAppConfigs();
|
||||
}
|
||||
}
|
||||
|
||||
public void onSaveCopyFormatString(View view) {
|
||||
if(showPreViewResult(metTimeStampCopyFormatString, mtvTimeStampCopyFormatString)) {
|
||||
AppConfigsUtil.getInstance(this).getAppConfigsModel().setTimeStampCopyFormatString(metTimeStampCopyFormatString.getText().toString());
|
||||
AppConfigsUtil.getInstance(this).saveAppConfigs();
|
||||
}
|
||||
}
|
||||
|
||||
boolean showPreViewResult(EditText etFormat, TextView tvShow) {
|
||||
try {
|
||||
long currentMillis = System.currentTimeMillis();
|
||||
Instant instant = Instant.ofEpochMilli(currentMillis);
|
||||
LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
|
||||
String szTimeStampFormatString = etFormat.getText().toString();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(szTimeStampFormatString);
|
||||
String formattedDateTime = ldt.format(formatter);
|
||||
tvShow.setText(formattedDateTime);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -18,11 +18,23 @@ public class AppConfigsModel extends BaseBean {
|
||||
|
||||
// 是否启动服务
|
||||
boolean isEnableService;
|
||||
// 时间戳显示格式
|
||||
String timeStampFormatString;
|
||||
// 时间戳拷贝格式
|
||||
String timeStampCopyFormatString;
|
||||
|
||||
public AppConfigsModel() {
|
||||
this.isEnableService = false;
|
||||
this.timeStampFormatString = "yyyy-MM-dd HH:mm:ss";
|
||||
this.timeStampCopyFormatString = "yyyy_MM_dd-HH_mm_ss";
|
||||
}
|
||||
|
||||
public void setTimeStampCopyFormatString(String timeStampCopyFormatString) {
|
||||
this.timeStampCopyFormatString = timeStampCopyFormatString;
|
||||
}
|
||||
|
||||
public String getTimeStampCopyFormatString() {
|
||||
return timeStampCopyFormatString;
|
||||
}
|
||||
|
||||
public void setTimeStampFormatString(String timeStampFormatString) {
|
||||
|
@ -15,7 +15,7 @@ public class ButtonClickReceiver extends BroadcastReceiver {
|
||||
|
||||
public static final String TAG = "ButtonClickReceiver";
|
||||
|
||||
public static final String BUTTON_COPYTIMESTAMP_ACTION = "com.example.BUTTON_CLICK_ACTION";
|
||||
public static final String BUTTON_COPYTIMESTAMP_ACTION = "cc.winboll.studio.timestamp.receivers.ButtonClickReceiver.BUTTON_COPYTIMESTAMP_ACTION";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
@ -7,16 +7,14 @@ package cc.winboll.studio.timestamp.utils;
|
||||
*/
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.widget.RemoteViews;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import cc.winboll.studio.timestamp.MainActivity;
|
||||
import cc.winboll.studio.timestamp.R;
|
||||
import cc.winboll.studio.timestamp.views.TimeStampView;
|
||||
import android.widget.TextView;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import cc.winboll.studio.timestamp.R;
|
||||
import cc.winboll.studio.timestamp.receivers.ButtonClickReceiver;
|
||||
|
||||
public class TimeStampRemoteViewsUtil {
|
||||
|
||||
@ -66,10 +64,21 @@ public class TimeStampRemoteViewsUtil {
|
||||
// 这里虽然不能直接设置字体大小,但可以通过反射等方式尝试(不推荐,且有兼容性问题)
|
||||
|
||||
// 创建点击通知后的意图
|
||||
Intent intent = new Intent(mContext, MainActivity.class);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
//Intent intent = new Intent(mContext, MainActivity.class);
|
||||
//PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
// 设置通知的点击事件
|
||||
//mRemoteViews.setOnClickPendingIntent(R.id.btn_copytimestamp, pendingIntent);
|
||||
|
||||
// 创建点击按钮后要发送的广播 Intent
|
||||
Intent broadcastIntent = new Intent(ButtonClickReceiver.BUTTON_COPYTIMESTAMP_ACTION);
|
||||
android.app.PendingIntent pendingIntent = android.app.PendingIntent.getBroadcast(
|
||||
mContext,
|
||||
0,
|
||||
broadcastIntent,
|
||||
android.app.PendingIntent.FLAG_UPDATE_CURRENT
|
||||
);
|
||||
|
||||
// 为按钮设置点击事件
|
||||
mRemoteViews.setOnClickPendingIntent(R.id.btn_copytimestamp, pendingIntent);
|
||||
|
||||
// 构建通知
|
||||
|
@ -39,9 +39,17 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<cc.winboll.studio.timestamp.views.TimeStampView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Show Format :"
|
||||
android:paddingRight="10dp"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Text"
|
||||
android:id="@+id/tv_timestampformatstring"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@ -61,8 +69,52 @@
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Save Format"
|
||||
android:id="@+id/btn_saveformatstring"/>
|
||||
android:text="ApplySave"
|
||||
android:id="@+id/btn_saveformatstring"
|
||||
android:textAllCaps="false"
|
||||
android:onClick="onSaveFormatString"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Copy Format :"
|
||||
android:paddingRight="10dp"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Text"
|
||||
android:id="@+id/tv_timestampcopyformatstring"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp">
|
||||
|
||||
<EditText
|
||||
android:layout_width="0dp"
|
||||
android:ems="10"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/et_timestampcopyformatstring"
|
||||
android:layout_weight="1.0"/>
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="ApplyCopy"
|
||||
android:id="@+id/btn_savecopyformatstring"
|
||||
android:textAllCaps="false"
|
||||
android:onClick="onSaveCopyFormatString"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user