This commit is contained in:
ZhanGSKen 2025-05-05 15:43:41 +08:00
parent 2f2512cd76
commit 466e061aa8
10 changed files with 380 additions and 233 deletions

View File

@ -1,8 +1,8 @@
#Created by .winboll/winboll_app_build.gradle #Created by .winboll/winboll_app_build.gradle
#Mon May 05 04:37:03 GMT 2025 #Mon May 05 07:42:42 GMT 2025
stageCount=0 stageCount=0
libraryProject= libraryProject=
baseVersion=15.0 baseVersion=15.0
publishVersion=15.0.0 publishVersion=15.0.0
buildCount=26 buildCount=63
baseBetaVersion=15.0.1 baseBetaVersion=15.0.1

View File

@ -13,7 +13,8 @@ import android.content.ServiceConnection;
import android.os.IBinder; import android.os.IBinder;
import cc.winboll.studio.timestamp.AssistantService; import cc.winboll.studio.timestamp.AssistantService;
import cc.winboll.studio.timestamp.MainService; import cc.winboll.studio.timestamp.MainService;
import cc.winboll.studio.timestamp.models.AppConfigs; import cc.winboll.studio.timestamp.models.AppConfigsModel;
import cc.winboll.studio.timestamp.utils.AppConfigsUtil;
import cc.winboll.studio.timestamp.utils.ServiceUtil; import cc.winboll.studio.timestamp.utils.ServiceUtil;
public class AssistantService extends Service { public class AssistantService extends Service {
@ -48,7 +49,7 @@ public class AssistantService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) { public int onStartCommand(Intent intent, int flags, int startId) {
//LogUtils.d(TAG, "call onStartCommand(...)"); //LogUtils.d(TAG, "call onStartCommand(...)");
run(); run();
AppConfigs appConfigs = AppConfigs.getInstance(AssistantService.this).loadAppConfigs(); AppConfigsModel appConfigs = AppConfigsUtil.getInstance(AssistantService.this).loadAppConfigs();
return appConfigs.isEnableService() ? Service.START_STICKY: super.onStartCommand(intent, flags, startId); return appConfigs.isEnableService() ? Service.START_STICKY: super.onStartCommand(intent, flags, startId);
} }
@ -70,7 +71,7 @@ public class AssistantService extends Service {
// //
void run() { void run() {
//LogUtils.d(TAG, "call run()"); //LogUtils.d(TAG, "call run()");
AppConfigs appConfigs = AppConfigs.getInstance(AssistantService.this).loadAppConfigs(); AppConfigsModel appConfigs = AppConfigsUtil.getInstance(AssistantService.this).loadAppConfigs();
if (appConfigs.isEnableService()) { if (appConfigs.isEnableService()) {
if (mIsThreadAlive == false) { if (mIsThreadAlive == false) {
// 设置运行状态 // 设置运行状态
@ -103,7 +104,7 @@ public class AssistantService extends Service {
@Override @Override
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
//LogUtils.d(TAG, "call onServiceDisconnected(...)"); //LogUtils.d(TAG, "call onServiceDisconnected(...)");
AppConfigs appConfigs = AppConfigs.getInstance(AssistantService.this).loadAppConfigs(); AppConfigsModel appConfigs = AppConfigsUtil.getInstance(AssistantService.this).loadAppConfigs();
if (appConfigs.isEnableService()) { if (appConfigs.isEnableService()) {
wakeupAndBindMain(); wakeupAndBindMain();
} }

View File

@ -2,12 +2,12 @@ package cc.winboll.studio.timestamp;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Switch;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import cc.winboll.studio.libappbase.LogView; import cc.winboll.studio.libappbase.LogView;
import cc.winboll.studio.timestamp.utils.AppConfigsUtil;
import com.hjq.toast.ToastUtils; import com.hjq.toast.ToastUtils;
import android.widget.Switch;
import cc.winboll.studio.timestamp.models.AppConfigs;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
@ -23,7 +23,7 @@ public class MainActivity extends AppCompatActivity {
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
mswEnableMainService = findViewById(R.id.activitymainSwitch1); mswEnableMainService = findViewById(R.id.activitymainSwitch1);
mswEnableMainService.setChecked(AppConfigs.getInstance(this).loadAppConfigs().isEnableService()); mswEnableMainService.setChecked(AppConfigsUtil.getInstance(this).loadAppConfigs().isEnableService());
mLogView = findViewById(R.id.logview); mLogView = findViewById(R.id.logview);

View File

@ -11,47 +11,38 @@ import android.app.Service;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection; import android.content.ServiceConnection;
import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.os.Message;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import android.widget.TextView; import android.widget.TextView;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import cc.winboll.studio.libappbase.LogUtils; import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.timestamp.AssistantService; import cc.winboll.studio.timestamp.AssistantService;
import cc.winboll.studio.timestamp.MainService; import cc.winboll.studio.timestamp.MainService;
import cc.winboll.studio.timestamp.models.AppConfigs; import cc.winboll.studio.timestamp.models.AppConfigsModel;
import cc.winboll.studio.timestamp.receivers.ButtonClickReceiver; import cc.winboll.studio.timestamp.receivers.ButtonClickReceiver;
import cc.winboll.studio.timestamp.utils.AppConfigsUtil;
import cc.winboll.studio.timestamp.utils.NotificationHelper; import cc.winboll.studio.timestamp.utils.NotificationHelper;
import cc.winboll.studio.timestamp.utils.ServiceUtil; import cc.winboll.studio.timestamp.utils.ServiceUtil;
import java.lang.ref.WeakReference;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import android.app.NotificationManager;
import android.content.IntentFilter;
public class MainService extends Service { public class MainService extends Service {
public static String TAG = "MainService"; public static String TAG = "MainService";
public static final int MSG_UPDATE_TIMESTAMP = 0;
ButtonClickReceiver mButtonClickReceiver; ButtonClickReceiver mButtonClickReceiver;
Intent intentMainService;
Intent mButtonBroadcastIntent;
PendingIntent mButtonPendingIntent;
NotificationHelper mNotificationHelper; NotificationHelper mNotificationHelper;
Notification notification; Notification mNotification;
RemoteViews mRemoteViews; RemoteViews mRemoteViews;
TextView mtvTimeStamp; TextView mtvTimeStamp;
Timer mTimer; Timer mTimer;
private static boolean _mIsServiceAlive; private static boolean _mIsServiceAlive;
public static final String EXTRA_APKFILEPATH = "EXTRA_APKFILEPATH"; public static final String EXTRA_APKFILEPATH = "EXTRA_APKFILEPATH";
final static int MSG_INSTALL_APK = 0; final static int MSG_INSTALL_APK = 0;
MyHandler mMyHandler; //MyHandler mMyHandler;
MyServiceConnection mMyServiceConnection; MyServiceConnection mMyServiceConnection;
MainActivity mInstallCompletedFollowUpActivity; MainActivity mInstallCompletedFollowUpActivity;
@ -63,21 +54,10 @@ public class MainService extends Service {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
// 创建 RemoteViews 对象并使用包含自定义 View 的布局
mRemoteViews = new RemoteViews(getPackageName(), R.layout.remoteviews_timestamp); mRemoteViews = new RemoteViews(getPackageName(), R.layout.remoteviews_timestamp);
intentMainService = new Intent(this, MainActivity.class);
// 创建点击按钮后要发送的广播 Intent
mButtonBroadcastIntent = new Intent(ButtonClickReceiver.BUTTON_COPYTIMESTAMP_ACTION);
mButtonPendingIntent = PendingIntent.getBroadcast(
this, // 上下文
0, // 请求码用于区分不同的 PendingIntent
mButtonBroadcastIntent, // Intent
PendingIntent.FLAG_UPDATE_CURRENT // 标志位用于更新已存在的 PendingIntent
);
// 为按钮设置点击事件
mRemoteViews.setOnClickPendingIntent(R.id.btn_copytimestamp, mButtonPendingIntent);
// 创建广播接收器实例 // 创建广播接收器实例
mButtonClickReceiver = new ButtonClickReceiver(); mButtonClickReceiver = new ButtonClickReceiver();
@ -86,10 +66,10 @@ public class MainService extends Service {
// 注册广播接收器 // 注册广播接收器
registerReceiver(mButtonClickReceiver, filter); registerReceiver(mButtonClickReceiver, filter);
LogUtils.d(TAG, "onCreate()"); LogUtils.d(TAG, "onCreate()");
_mIsServiceAlive = false; _mIsServiceAlive = false;
mMyHandler = new MyHandler(MainService.this); //mMyHandler = new MyHandler(MainService.this);
if (mMyServiceConnection == null) { if (mMyServiceConnection == null) {
mMyServiceConnection = new MyServiceConnection(); mMyServiceConnection = new MyServiceConnection();
} }
@ -98,7 +78,7 @@ public class MainService extends Service {
} }
private void run() { private void run() {
AppConfigs appConfigs = AppConfigs.getInstance(MainService.this).loadAppConfigs(); AppConfigsModel appConfigs = AppConfigsUtil.getInstance(MainService.this).loadAppConfigs();
if (appConfigs.isEnableService()) { if (appConfigs.isEnableService()) {
if (_mIsServiceAlive == false) { if (_mIsServiceAlive == false) {
// 设置运行状态 // 设置运行状态
@ -107,23 +87,14 @@ public class MainService extends Service {
// 显示前台通知栏 // 显示前台通知栏
mNotificationHelper = new NotificationHelper(this); mNotificationHelper = new NotificationHelper(this);
//notification = helper.showForegroundNotification(intent, getString(R.string.app_name), getString(R.string.text_aboutservernotification)); //notification = helper.showForegroundNotification(intent, getString(R.string.app_name), getString(R.string.text_aboutservernotification));
notification = mNotificationHelper.showCustomForegroundNotification(intentMainService, mRemoteViews, mRemoteViews); mNotification = mNotificationHelper.showCustomForegroundNotification(new Intent(this, MainActivity.class), mRemoteViews, mRemoteViews);
startForeground(NotificationHelper.FOREGROUND_NOTIFICATION_ID, notification); startForeground(NotificationHelper.FOREGROUND_NOTIFICATION_ID, mNotification);
// 唤醒守护进程 // 唤醒守护进程
wakeupAndBindAssistant(); wakeupAndBindAssistant();
LogUtils.d(TAG, "running..."); LogUtils.d(TAG, "running...");
mTimer = new Timer();
TimerTask task = new TimerTask() {
@Override
public void run() {
//System.out.println("定时任务执行了");
mMyHandler.sendEmptyMessage(MSG_UPDATE_TIMESTAMP);
}
};
// 延迟1秒后开始执行之后每隔2秒执行一次
mTimer.schedule(task, 1000, 2000);
} else { } else {
@ -149,14 +120,16 @@ public class MainService extends Service {
LogUtils.d(TAG, "onStartCommand"); LogUtils.d(TAG, "onStartCommand");
run(); run();
AppConfigs appConfigs = AppConfigs.getInstance(MainService.this).loadAppConfigs(); AppConfigsModel appConfigs = AppConfigsUtil.getInstance(MainService.this).loadAppConfigs();
return appConfigs.isEnableService() ? Service.START_STICKY: super.onStartCommand(intent, flags, startId); return appConfigs.isEnableService() ? Service.START_STICKY: super.onStartCommand(intent, flags, startId);
} }
public static void setMainServiceStatus(Context context, boolean isEnable) { public static void setMainServiceStatus(Context context, boolean isEnable) {
AppConfigs appConfigs = AppConfigs.getInstance(context).loadAppConfigs(); AppConfigsModel appConfigs = AppConfigsUtil.getInstance(context).loadAppConfigs();
appConfigs.setIsEnableService(isEnable); appConfigs.setIsEnableService(isEnable);
AppConfigsUtil.getInstance(context).saveAppConfigs();
Intent intent = new Intent(context, MainService.class); Intent intent = new Intent(context, MainService.class);
if (isEnable) { if (isEnable) {
context.startService(intent); context.startService(intent);
@ -176,7 +149,7 @@ public class MainService extends Service {
@Override @Override
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
//LogUtils.d(TAG, "call onServiceConnected(...)"); //LogUtils.d(TAG, "call onServiceConnected(...)");
AppConfigs appConfigs = AppConfigs.getInstance(MainService.this).loadAppConfigs(); AppConfigsModel appConfigs = AppConfigsUtil.getInstance(MainService.this).loadAppConfigs();
if (appConfigs.isEnableService()) { if (appConfigs.isEnableService()) {
// 唤醒守护进程 // 唤醒守护进程
wakeupAndBindAssistant(); wakeupAndBindAssistant();
@ -194,46 +167,43 @@ public class MainService extends Service {
} }
} }
void updateTimeStamp() { // void updateTimeStamp() {
long currentMillis = System.currentTimeMillis(); // long currentMillis = System.currentTimeMillis();
Instant instant = Instant.ofEpochMilli(currentMillis); // Instant instant = Instant.ofEpochMilli(currentMillis);
LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneId.systemDefault()); // LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); // String szTimeStampFormatString = AppConfigs.getInstance(this).getTimeStampFormatString();
String formattedDateTime = ldt.format(formatter); // DateTimeFormatter formatter = DateTimeFormatter.ofPattern(szTimeStampFormatString);
//System.out.println(formattedDateTime); // String formattedDateTime = ldt.format(formatter);
mRemoteViews.setTextViewText(R.id.tv_timestamp, formattedDateTime); // //System.out.println(formattedDateTime);
notification = mNotificationHelper.showCustomForegroundNotification(intentMainService, mRemoteViews, mRemoteViews); // mRemoteViews.setTextViewText(R.id.tv_timestamp, formattedDateTime);
//startForeground(NotificationHelper.FOREGROUND_NOTIFICATION_ID, notification); // notification = mNotificationHelper.showCustomForegroundNotification(intentMainService, mRemoteViews, mRemoteViews);
} // //startForeground(NotificationHelper.FOREGROUND_NOTIFICATION_ID, notification);
// }
// //
// 服务事务处理类 // //
// // // 服务事务处理类
class MyHandler extends Handler { // //
WeakReference<MainService> weakReference; // class MyHandler extends Handler {
MyHandler(MainService service) { // WeakReference<MainService> weakReference;
weakReference = new WeakReference<MainService>(service); // MyHandler(MainService service) {
} // weakReference = new WeakReference<MainService>(service);
public void handleMessage(Message message) { // }
MainService theService = weakReference.get(); // public void handleMessage(Message message) {
switch (message.what) { // MainService theService = weakReference.get();
case MSG_UPDATE_TIMESTAMP: // switch (message.what) {
{ // case MSG_UPDATE_TIMESTAMP:
if (theService != null) { // {
theService.updateTimeStamp(); // if (theService != null) {
} // theService.updateTimeStamp();
break; // }
} // break;
default: // }
break; // default:
} // break;
super.handleMessage(message); // }
} // super.handleMessage(message);
// }
//
} //
// }
public void sendUpdateTimeStampMessage() {
}
} }

View File

@ -1,128 +0,0 @@
package cc.winboll.studio.timestamp.models;
/**
* @Author ZhanGSKen
* @Date 2025/05/05 09:51
* @Describe 应用配置数据模型
*/
import android.content.Context;
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.timestamp.models.AppConfigs;
import cc.winboll.studio.timestamp.utils.FileUtil;
import java.io.IOException;
import java.io.Serializable;
import java.io.StringReader;
import java.io.StringWriter;
public class AppConfigs implements Serializable {
public static final String TAG = "AppConfigs";
volatile static AppConfigs _AppConfigs;
Context mContext;
// 是否启动服务
boolean isEnableService;
AppConfigs(Context context) {
this.mContext = context;
this.isEnableService = false;
}
public synchronized static AppConfigs getInstance(Context context) {
if (_AppConfigs == null) {
_AppConfigs = new AppConfigs(context);
_AppConfigs.loadAppConfigs();
}
return _AppConfigs;
}
public void setIsEnableService(boolean isEnableService) {
this.isEnableService = isEnableService;
}
public boolean isEnableService() {
return isEnableService;
}
@Override
public String toString() {
// 创建 JsonWriter 对象
StringWriter stringWriter = new StringWriter();
JsonWriter writer = new
JsonWriter(stringWriter);
try {
// 开始 JSON 对象
writer.beginObject();
// 写入键值对
writer.name("isEnableService").value(this.isEnableService);
// 结束 JSON 对象
writer.endObject();
return stringWriter.toString();
} catch (IOException e) {
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
}
// 获取 JSON 字符串
return "";
}
public AppConfigs parseAppConfigs(String szAppConfigs) {
// 创建 JsonWriter 对象
StringReader stringReader = new StringReader(szAppConfigs);
JsonReader jsonReader = new
JsonReader(stringReader);
try {
// 开始 JSON 对象
jsonReader.beginObject();
// 写入键值对
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
if (name.equals("isEnableService")) {
setIsEnableService(jsonReader.nextBoolean());
} else {
jsonReader.skipValue();
}
}
// 结束 JSON 对象
jsonReader.endObject();
return this;
} catch (IOException e) {
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
}
// 获取 JSON 字符串
return null;
}
static String getDataPath(Context context) {
return context.getExternalFilesDir(TAG) + "/" + TAG + ".json";
}
public AppConfigs loadAppConfigs() {
AppConfigs appConfigs = null;
try {
String szJson = FileUtil.readFile(getDataPath(mContext));
appConfigs = parseAppConfigs(szJson);
if (appConfigs != null) {
_AppConfigs = appConfigs;
}
} catch (IOException e) {
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
}
return _AppConfigs;
}
public void saveAppConfigs(AppConfigs appConfigs) {
try {
String szJson = appConfigs.toString();
FileUtil.writeFile(getDataPath(mContext), szJson);
} catch (IOException e) {
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
}
}
}

View File

@ -0,0 +1,83 @@
package cc.winboll.studio.timestamp.models;
/**
* @Author ZhanGSKen
* @Date 2025/05/05 09:51
* @Describe 应用配置数据模型
*/
import android.content.Context;
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.libappbase.BaseBean;
import cc.winboll.studio.timestamp.models.AppConfigsModel;
import java.io.IOException;
public class AppConfigsModel extends BaseBean {
public static final String TAG = "AppConfigs";
// 是否启动服务
boolean isEnableService;
String timeStampFormatString;
public AppConfigsModel() {
this.isEnableService = false;
this.timeStampFormatString = "yyyy-MM-dd HH:mm:ss";
}
public void setTimeStampFormatString(String timeStampFormatString) {
this.timeStampFormatString = timeStampFormatString;
}
public String getTimeStampFormatString() {
return timeStampFormatString;
}
public void setIsEnableService(boolean isEnableService) {
this.isEnableService = isEnableService;
}
public boolean isEnableService() {
return isEnableService;
}
@Override
public String getName() {
return AppConfigsModel.class.getName();
}
@Override
public void writeThisToJsonWriter(JsonWriter jsonWriter) throws IOException {
super.writeThisToJsonWriter(jsonWriter);
jsonWriter.name("isEnableService").value(isEnableService());
jsonWriter.name("timeStampFormatString").value(getTimeStampFormatString());
}
@Override
public boolean initObjectsFromJsonReader(JsonReader jsonReader, String name) throws IOException {
if (super.initObjectsFromJsonReader(jsonReader, name)) { return true; } else {
if (name.equals("isEnableService")) {
setIsEnableService(jsonReader.nextBoolean());
} else if (name.equals("timeStampFormatString")) {
setTimeStampFormatString(jsonReader.nextString());
} else {
return false;
}
}
return true;
}
@Override
public BaseBean readBeanFromJsonReader(JsonReader jsonReader) throws IOException {
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String name = jsonReader.nextName();
if (!initObjectsFromJsonReader(jsonReader, name)) {
jsonReader.skipValue();
}
}
// 结束 JSON 对象
jsonReader.endObject();
return this;
}
}

View File

@ -0,0 +1,58 @@
package cc.winboll.studio.timestamp.utils;
/**
* @Author ZhanGSKen
* @Date 2025/05/05 14:00
* @Describe AppConfigsUtil
*/
import android.content.Context;
import android.util.JsonReader;
import android.util.JsonWriter;
import cc.winboll.studio.libappbase.BaseBean;
import cc.winboll.studio.timestamp.models.AppConfigsModel;
import java.io.IOException;
public class AppConfigsUtil {
public static final String TAG = "AppConfigsUtil";
volatile static AppConfigsUtil _AppConfigsUtil;
Context mContext;
AppConfigsModel mAppConfigsModel;
AppConfigsUtil(Context context) {
this.mContext = context;
}
public synchronized static AppConfigsUtil getInstance(Context context){
if(_AppConfigsUtil == null) {
_AppConfigsUtil = new AppConfigsUtil(context);
_AppConfigsUtil.loadAppConfigs();
}
return _AppConfigsUtil;
}
public AppConfigsModel getAppConfigsModel() {
return mAppConfigsModel;
}
public AppConfigsModel loadAppConfigs() {
AppConfigsModel appConfigsModel = null;
appConfigsModel = AppConfigsModel.loadBean(mContext, AppConfigsModel.class);
if (appConfigsModel != null) {
mAppConfigsModel = appConfigsModel;
} else {
saveAppConfigs(new AppConfigsModel());
_AppConfigsUtil = this;
}
return mAppConfigsModel;
}
public void saveAppConfigs(AppConfigsModel appConfigsModel) {
AppConfigsModel.saveBean(mContext, appConfigsModel);
}
public void saveAppConfigs() {
AppConfigsModel.saveBean(mContext, mAppConfigsModel);
}
}

View File

@ -0,0 +1,126 @@
package cc.winboll.studio.timestamp.views;
/**
* @Author ZhanGSKen
* @Date 2025/05/05 12:53
* @Describe TimeStampView
*/
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
import cc.winboll.studio.libappbase.LogUtils;
import cc.winboll.studio.timestamp.R;
import cc.winboll.studio.timestamp.utils.AppConfigsUtil;
import com.hjq.toast.ToastUtils;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Timer;
import java.util.TimerTask;
public class TimeStampView extends TextView {
public static final String TAG = "TimeStampView";
public static final int MSG_UPDATE_TIMESTAMP = 0;
private Paint paint;
// Context mContext;
// Timer mTimer;
// TextView mtvTimeStamp;
// MyHandler mMyHandler;
public TimeStampView(Context context) {
super(context);
//initView(context);
init();
}
public TimeStampView(Context context, AttributeSet attrs) {
super(context, attrs);
//initView(context);
init();
}
public TimeStampView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
//initView(context);
init();
}
private void init() {
paint = new Paint();
paint.setColor(Color.RED);
paint.setStyle(Paint.Style.FILL);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawCircle(50, 50, 30, paint);
}
// void initView(Context context) {
// View viewMain = inflate(context, R.layout.view_timestamp, null);
// this.mContext = context;
// mtvTimeStamp = viewMain.findViewById(R.id.tv_timestamp);
// addView(viewMain);
//
// mMyHandler = new MyHandler();
//
// mTimer = new Timer();
// TimerTask task = new TimerTask() {
// @Override
// public void run() {
// //System.out.println("定时任务执行了");
// mMyHandler.sendEmptyMessage(MSG_UPDATE_TIMESTAMP);
//
// }
// };
// // 延迟1秒后开始执行之后每隔100毫秒执行一次
// mTimer.schedule(task, 1000, 1000);
// }
// public void updateTimeStamp() {
// try {
// long currentMillis = System.currentTimeMillis();
// Instant instant = Instant.ofEpochMilli(currentMillis);
// LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
// String szTimeStampFormatString = AppConfigsUtil.getInstance(this.mContext).getAppConfigsModel().getTimeStampFormatString();
// DateTimeFormatter formatter = DateTimeFormatter.ofPattern(szTimeStampFormatString);
// String formattedDateTime = ldt.format(formatter);
// //System.out.println(formattedDateTime);
// mtvTimeStamp.setText(formattedDateTime);
// } catch (Exception e) {
// LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
// ToastUtils.show(e);
// }
// }
//
// 服务事务处理类
//
// class MyHandler extends Handler {
//
// public void handleMessage(Message message) {
// switch (message.what) {
// case MSG_UPDATE_TIMESTAMP:
// {
// updateTimeStamp();
// break;
// }
// default:
// break;
// }
// super.handleMessage(message);
// }
// }
}

View File

@ -22,7 +22,8 @@
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:padding="10dp">
<Switch <Switch
android:layout_width="match_parent" android:layout_width="match_parent"
@ -33,6 +34,38 @@
</LinearLayout> </LinearLayout>
<LinearLayout
android:orientation="horizontal"
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"/>
</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_timestampformatstring"
android:layout_weight="1.0"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save Format"
android:id="@+id/btn_saveformatstring"/>
</LinearLayout>
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -8,11 +8,15 @@
android:gravity="center_vertical"> android:gravity="center_vertical">
<TextView <TextView
android:layout_width="0dp" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Text" android:text="Text1"/>
android:id="@+id/tv_timestamp"
android:layout_weight="1.0"/> <cc.winboll.studio.timestamp.views.TimeStampView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Text2"
android:id="@+id/remoteviewstimestampTextView1"/>
<Button <Button
android:id="@+id/btn_copytimestamp" android:id="@+id/btn_copytimestamp"