Commit 87e3f58e authored by wanglei's avatar wanglei

同步功能

parent 8dace8a3
......@@ -14,7 +14,7 @@ android {
defaultConfig {
applicationId "com.test.easy.easycleanerjunk"
minSdk 24
targetSdk 33
targetSdk 34
versionCode 1
versionName "1.0"
ndk {
......
......@@ -33,7 +33,7 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.SmartCleaner"
tools:targetApi="31">
tools:targetApi="34">
<activity
android:name=".activity.splash.NewSplashActivity"
......
......@@ -11,6 +11,7 @@ import com.test.easy.easycleanerjunk.helps.ConfigHelper
import com.test.easy.easycleanerjunk.helps.ConfigHelper.fcmNotification
import com.test.easy.easycleanerjunk.helps.ConfigHelper.remainNotification
import com.test.easy.easycleanerjunk.service.PermanentNotificationService
import com.test.easy.easycleanerjunk.service.PermanentNotificationService.Companion.startNotification
import com.test.easy.easycleanerjunk.view.RateStarPop
......@@ -61,13 +62,4 @@ class SettingActivity : BaseActivity<ActivitySettingBinding>() {
}
}
private fun startNotification() {
val intent = Intent(this, PermanentNotificationService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent)
} else {
startService(intent)
}
}
}
\ No newline at end of file
......@@ -2,6 +2,8 @@ package com.test.easy.easycleanerjunk.activity.home
import android.graphics.Color
import android.graphics.Typeface
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.viewpager2.adapter.FragmentStateAdapter
......@@ -12,6 +14,7 @@ import com.test.easy.easycleanerjunk.fragment.ToolsFragment
import com.test.easy.easycleanerjunk.helps.BaseActivity
import com.test.easy.easycleanerjunk.helps.EventUtils
import com.test.easy.easycleanerjunk.utils.BarUtils
import com.test.easy.easycleanerjunk.view.NotifyTips
import com.test.easy.easycleanerjunk.view.RateStarPop
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
......@@ -35,10 +38,14 @@ class NewMainActivity : BaseActivity<ActivityMainBinding>() {
ActivityMainBinding.inflate(layoutInflater)
}
@RequiresApi(Build.VERSION_CODES.O)
override fun initView() {
BarUtils.setStatusBarLightMode(this, true)
BarUtils.setStatusBarColor(this, Color.TRANSPARENT)
EventUtils.event("page_home")
if (!hasNotifications()) {
NotifyTips(this) {}.show()
}
binding.idVp.run {
adapter = object : FragmentStateAdapter(this@NewMainActivity) {
override fun getItemCount(): Int {
......
......@@ -17,6 +17,7 @@ import com.test.easy.easycleanerjunk.helps.ConfigHelper.remainNotification
import com.test.easy.easycleanerjunk.helps.EventUtils
import com.test.easy.easycleanerjunk.helps.ads.AdmobUtils
import com.test.easy.easycleanerjunk.service.PermanentNotificationService
import com.test.easy.easycleanerjunk.service.PermanentNotificationService.Companion.startNotification
import com.test.easy.easycleanerjunk.utils.BarUtils
@SuppressLint("CustomSplashScreen")
......@@ -82,16 +83,6 @@ class NewSplashActivity : BaseActivity<ActivityLayoutSplashBinding>(),
}
}
private fun startNotification() {
if (remainNotification) {
val intent = Intent(this, PermanentNotificationService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent)
} else {
startService(intent)
}
}
}
override fun onProgressMax() {
Handler().postDelayed({
......
......@@ -12,6 +12,7 @@ import android.os.HandlerThread;
import android.util.Log;
import android.widget.RemoteViews;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import com.test.easy.easycleanerjunk.MyApplication;
......@@ -33,7 +34,7 @@ public class NotificationUtil {
*
* @param context 上下文对象
*/
public static void sendCustomNotification(Context context, Intent intent, RemoteViews remoteViews) {
public static void sendCustomNotification(Context context, Intent intent, RemoteViews bigRemoteViews, RemoteViews smallRemoteViews) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
......@@ -42,10 +43,8 @@ public class NotificationUtil {
notificationManager.createNotificationChannel(channel);
}
// Create an Intent for the activity you want to open when the notification is clicked
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE);
Intent deleteIntent = new Intent(context, CloseNotificationReceiver.class);
deleteIntent.setAction("DELETE_NOTIFICATION");
PendingIntent deletePendingIntent = PendingIntent.getBroadcast(context, 0, deleteIntent, PendingIntent.FLAG_MUTABLE);
......@@ -58,11 +57,20 @@ public class NotificationUtil {
.setContentIntent(pendingIntent)
.setDeleteIntent(deletePendingIntent)
.setPriority(NotificationCompat.PRIORITY_MAX)
.setContent(remoteViews)
.setCustomHeadsUpContentView(remoteViews)
.setCustomBigContentView(remoteViews)
.setCustomContentView(remoteViews)
.setAutoCancel(true);
RemoteViews small = bigRemoteViews;
//Android 12以下需要适配小RemoteViews
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
small = smallRemoteViews;
}
builder.setContent(small);
builder.setCustomHeadsUpContentView(small);
builder.setCustomContentView(small);
builder.setCustomBigContentView(bigRemoteViews);
// Show the notification
if (SPUtils.getInstance().getInt("actionS", 0) == 1) {
notificationManager.notify(intent.getIntExtra("actionId", 0), builder.build());
......@@ -134,7 +142,8 @@ public class NotificationUtil {
public static void sendNotification(Context context, int actionId) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.notification_common_notify);
RemoteViews bigRemoteViews = new RemoteViews(context.getPackageName(), R.layout.notification_common_notify);
RemoteViews smallRemoteViews = new RemoteViews(context.getPackageName(), R.layout.notification_common_notification_small);
//功能触发push actionId 主动发送
String desc;
String btn;
......@@ -174,30 +183,32 @@ public class NotificationUtil {
} else {
return;
}
remoteViews.setImageViewResource(R.id.iv_icon, icon);
remoteViews.setTextViewText(R.id.tv_desc, desc);
remoteViews.setTextViewText(R.id.tv_btn, btn);
bigRemoteViews.setImageViewResource(R.id.iv_icon, icon);
bigRemoteViews.setTextViewText(R.id.tv_desc, desc);
bigRemoteViews.setTextViewText(R.id.tv_btn, btn);
smallRemoteViews.setImageViewResource(R.id.iv_icon, icon);
smallRemoteViews.setTextViewText(R.id.tv_desc, desc);
smallRemoteViews.setTextViewText(R.id.tv_btn, btn);
Intent cancelIntent = new Intent(context, CloseNotificationReceiver.class);
cancelIntent.setAction("CANCEL_NOTIFICATION");
cancelIntent.putExtra(CloseNotificationReceiver.id, actionId);
int flag = PendingIntent.FLAG_IMMUTABLE;
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
// flag = PendingIntent.FLAG_MUTABLE;
// } else {
// flag = PendingIntent.FLAG_IMMUTABLE;
// }
Intent intent = new Intent(context, NewSplashActivity.class);
intent.putExtra("actionId", actionId);
int btnRequestCode = new Random().nextInt(1000);
PendingIntent btnPendingIntent = PendingIntent.getActivity(context, btnRequestCode, intent, flag);
remoteViews.setOnClickPendingIntent(R.id.fl_btn, btnPendingIntent);
bigRemoteViews.setOnClickPendingIntent(R.id.fl_btn, btnPendingIntent);
smallRemoteViews.setOnClickPendingIntent(R.id.fl_btn, btnPendingIntent);
PendingIntent cancelPendingIntent = PendingIntent.getBroadcast(context, NOTIFICATION_ID, cancelIntent, flag);
remoteViews.setOnClickPendingIntent(R.id.fl_cancel, cancelPendingIntent);
sendCustomNotification(context, intent, remoteViews);
bigRemoteViews.setOnClickPendingIntent(R.id.fl_cancel, cancelPendingIntent);
sendCustomNotification(context, intent, bigRemoteViews, smallRemoteViews);
}
......
......@@ -15,7 +15,9 @@ import com.test.easy.easycleanerjunk.activity.ScreenShotActivity
import com.test.easy.easycleanerjunk.activity.SettingActivity
import com.test.easy.easycleanerjunk.activity.WhatsAppCleanerActivity
import com.test.easy.easycleanerjunk.activity.photocompress.photo.StartCompressionPhotoActivity
import com.test.easy.easycleanerjunk.bean.ConfigBean
import com.test.easy.easycleanerjunk.databinding.FragmentLayoutHomeBinding
import com.test.easy.easycleanerjunk.fcm.NotificationUtil.sendNotification
import com.test.easy.easycleanerjunk.helps.BaseFragment
import com.test.easy.easycleanerjunk.helps.KotlinExt.setOnClickListener
import com.test.easy.easycleanerjunk.utils.BarUtils
......@@ -35,7 +37,6 @@ class HomeFragment : BaseFragment<FragmentLayoutHomeBinding>() {
private var animator: ValueAnimator? = null
private var animPaused = false
private var rotationValue = 0f
private var animator2: ValueAnimator? = null
private fun startAnimation() {
animator = ValueAnimator.ofFloat(rotationValue, rotationValue + 360f).apply {
duration = 1000
......@@ -50,10 +51,6 @@ class HomeFragment : BaseFragment<FragmentLayoutHomeBinding>() {
}
start()
}
// animator2 = TranslateAnimation.ofFloat(transition, ).apply {
//
// start()
// }
}
override fun onResume() {
......
......@@ -2,6 +2,7 @@ package com.test.easy.easycleanerjunk.helps
import android.app.AppOpsManager
import android.app.Dialog
import android.app.NotificationManager
import android.content.Context
import android.content.Intent
import android.net.Uri
......@@ -218,4 +219,14 @@ abstract class BaseActivity<T : ViewBinding> : AppCompatActivity() {
}
}
fun hasNotifications(): Boolean {
val mNotificationManager = this.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
return mNotificationManager.importance != NotificationManager.IMPORTANCE_NONE
} else {
return true
}
}
}
\ No newline at end of file
......@@ -18,6 +18,7 @@ import com.test.easy.easycleanerjunk.activity.AppManagerActivity
import com.test.easy.easycleanerjunk.activity.BatteryInfoActivity
import com.test.easy.easycleanerjunk.activity.PrepareScanActivity
import com.test.easy.easycleanerjunk.activity.home.NewMainActivity
import com.test.easy.easycleanerjunk.helps.ConfigHelper
/**
......@@ -27,6 +28,17 @@ class PermanentNotificationService : Service() {
companion object {
var isRunning = false
fun Context.startNotification() {
if (ConfigHelper.remainNotification) {
val intent = Intent(this, PermanentNotificationService::class.java)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
startForegroundService(intent)
} else {
startService(intent)
}
}
}
}
......@@ -98,7 +110,7 @@ class PermanentNotificationService : Service() {
val builder = NotificationCompat.Builder(context, channelId)
builder.setCustomContentView(contentView)
builder.setLargeIcon(BitmapFactory.decodeResource(context.resources,R.mipmap.logo))
builder.setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.logo))
builder.setContentTitle(context.resources.getString(R.string.app_name))
builder.setCustomBigContentView(expendView)
builder.setContentIntent(pendingIntent) //设置PendingIntent
......
package com.test.easy.easycleanerjunk.view
import android.app.Activity
import android.content.Intent
import android.os.Build
import android.provider.Settings
import android.view.Gravity
import android.view.ViewGroup
import android.widget.PopupWindow
import androidx.annotation.RequiresApi
import androidx.core.view.updatePadding
import com.test.easy.easycleanerjunk.databinding.PopLayoutNotifyTipsBinding
import com.test.easy.easycleanerjunk.utils.BarUtils
class NotifyTips(private val activity: Activity, val onDismiss: () -> Unit) : PopupWindow() {
init {
width = ViewGroup.LayoutParams.MATCH_PARENT
height = ViewGroup.LayoutParams.MATCH_PARENT
isOutsideTouchable = false
isFocusable = true
isClippingEnabled = false
}
private val binding by lazy {
PopLayoutNotifyTipsBinding.inflate(activity.layoutInflater)
}
@RequiresApi(Build.VERSION_CODES.O)
fun show() {
contentView = binding.root
activity.window.decorView.post {
binding.root.updatePadding(top = BarUtils.getStatusBarHeight())
BarUtils.setStatusBarLightMode(activity, false)
showAtLocation(activity.window.decorView, Gravity.CENTER, 0, 0)
}
binding.idImgClose.setOnClickListener {
dismiss()
}
binding.idTvExperienceNow.setOnClickListener {
dismiss()
val intent = Intent()
intent.action = Settings.ACTION_APP_NOTIFICATION_SETTINGS
intent.putExtra(Settings.EXTRA_APP_PACKAGE, activity.packageName)
activity.startActivity(intent)
}
}
override fun dismiss() {
super.dismiss()
BarUtils.setStatusBarLightMode(activity, true)
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FF302F" />
<corners android:radius="13dp" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/shape_ffffff_r10"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:ignore="UselessParent">
<ImageView
android:id="@+id/iv_icon"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="8dp"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/tv_desc"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginHorizontal="8dp"
android:layout_weight="1"
android:gravity="center"
android:textColor="#000000"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="12dp"
android:background="@drawable/bg_ff302f_15"
android:paddingHorizontal="25dp"
android:paddingVertical="8dp"
android:text="View"
android:textColor="@color/white"
android:textSize="15sp"
tools:ignore="HardcodedText" />
</LinearLayout>
</FrameLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:id="@+id/id_frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#B3000000">
<com.noober.background.view.BLLinearLayout
android:id="@+id/id_ll_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginHorizontal="27dp"
android:orientation="vertical"
app:bl_corners_radius="10dp"
app:bl_solid_color="@color/white">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@mipmap/tanchuangbg"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/id_img_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"
android:src="@mipmap/guanbi"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:layout_marginBottom="5dp"
android:text="Don't miss important tips"
android:textSize="15sp"
android:textStyle="bold"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="8dp"
android:gravity="center"
android:text="Enable notifications to receive important \nsuggestions."
android:textColor="#666666"
android:textSize="13sp" />
<com.noober.background.view.BLTextView
android:id="@+id/id_tv_experience_now"
android:layout_width="241dp"
android:layout_height="42dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="24dp"
android:gravity="center"
android:text="Experience Now"
android:textColor="@color/white"
android:textSize="17sp"
app:bl_corners_radius="21dp"
app:bl_solid_color="@color/theme_color" />
</com.noober.background.view.BLLinearLayout>
</FrameLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment