Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanndroid committed May 29, 2022
0 parents commit 967cb38
Show file tree
Hide file tree
Showing 26 changed files with 1,102 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
*.iml
.gradle
/local.properties
.idea
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
41 changes: 41 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
plugins {
id 'com.android.application'
}

android {
compileSdk 32

defaultConfig {
applicationId "de.dlyt.yanndroid.dualwallpaper"
minSdk 26
targetSdk 32
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

configurations.all {
exclude group: 'androidx.appcompat', module: 'appcompat'
exclude group: 'androidx.core', module: 'core'
//exclude group: 'androidx.drawerlayout', module: 'drawerlayout'
//exclude group: 'androidx.viewpager', module: 'viewpager'
}

dependencies {
implementation 'io.github.oneuiproject:lib:1.0.0'
implementation 'io.github.oneuiproject.sesl:appcompat:1.0.0'
implementation 'io.github.oneuiproject.sesl:material:1.0.0'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
64 changes: 64 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.dlyt.yanndroid.dualwallpaper">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<uses-feature
android:name="android.software.live_wallpaper"
android:required="true" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/OneUITheme">

<service
android:name=".LiveWallpaper"
android:configChanges="uiMode|orientation"
android:enabled="true"
android:exported="true"
android:permission="android.permission.BIND_WALLPAPER">
<intent-filter>
<action android:name="android.service.wallpaper.WallpaperService" />
</intent-filter>
<meta-data
android:name="android.service.wallpaper"
android:resource="@xml/live_wallpaper" />
</service>

<service
android:name=".WallpaperService"
android:enabled="true"
android:exported="true"
android:process=":ws" />

<receiver
android:name=".BootReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>

<activity
android:name=".ui.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package de.dlyt.yanndroid.dualwallpaper;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.e("BootReceiver", intent.getAction());
if (context.getSharedPreferences("sp", Context.MODE_PRIVATE).getBoolean("use_service_switch", false))
context.startForegroundService(new Intent(context, WallpaperService.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package de.dlyt.yanndroid.dualwallpaper;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler;
import android.service.wallpaper.WallpaperService;
import android.view.SurfaceHolder;

public class LiveWallpaper extends WallpaperService {

private WallpaperUtil wallpaperUtil;
private DynamicThemeEngine dynamicThemeEngine;
private int uiMode = -1;

@Override
public Engine onCreateEngine() {
wallpaperUtil = new WallpaperUtil(this);
return dynamicThemeEngine = new DynamicThemeEngine(this);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
if (uiMode != newConfig.uiMode) {
//dynamicThemeEngine.update(newConfig);
wallpaperUtil.loadWallpaper(false, newConfig.uiMode != 33);
uiMode = newConfig.uiMode;
}
dynamicThemeEngine.update(newConfig);
//wallpaperUtil.loadWallpaper(false, newConfig.uiMode != 33);
}

private class DynamicThemeEngine extends Engine {
private final Handler handler = new Handler();
private final Runnable runnable = this::draw;
private boolean lightMode, portrait;

private boolean visible = true;

public DynamicThemeEngine(Context context) {
update(context.getResources().getConfiguration());
}

public void update(Configuration config) {
this.lightMode = config.uiMode != 33;
this.portrait = config.orientation == Configuration.ORIENTATION_PORTRAIT;
handler.post(runnable);
}

private void draw() {
SurfaceHolder holder = getSurfaceHolder();
Canvas canvas = null;
try {
canvas = holder.lockCanvas();
Bitmap bMap = BitmapFactory.decodeFile(wallpaperUtil.getWallpaperPath(true, lightMode));
Rect surfaceFrame = holder.getSurfaceFrame();

int cropH = !portrait ? 0 : (bMap.getWidth() - ((bMap.getHeight() / surfaceFrame.height()) * surfaceFrame.width())) / 2;
int cropV = portrait ? 0 : (bMap.getHeight() - ((bMap.getWidth() / surfaceFrame.width()) * surfaceFrame.height())) / 2;

BitmapDrawable d = new BitmapDrawable(bMap);
d.setBounds(-cropH, -cropV, surfaceFrame.width() + cropH, surfaceFrame.height() + cropV);
d.draw(canvas);
} finally {
if (canvas != null) holder.unlockCanvasAndPost(canvas);
}
handler.removeCallbacks(runnable);
if (visible) {
handler.post(runnable);
}
}

@Override
public void onVisibilityChanged(boolean visible) {
this.visible = visible;
if (visible) {
handler.post(runnable);
} else {
handler.removeCallbacks(runnable);
}
}

@Override
public void onSurfaceDestroyed(SurfaceHolder holder) {
super.onSurfaceDestroyed(holder);
this.visible = false;
handler.removeCallbacks(runnable);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package de.dlyt.yanndroid.dualwallpaper;

import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.IBinder;
import android.provider.Settings;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;

public class WallpaperService extends Service {

private WallpaperUtil wallpaperUtil;
private int uiMode;

@Override
public void onCreate() {
uiMode = getResources().getConfiguration().uiMode;
wallpaperUtil = new WallpaperUtil(this);
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.e("WallpaperService", "onStartCommand");
startForeground(3000, new NotificationCompat.Builder(this, "4000")
.setSmallIcon(dev.oneuiproject.oneui.R.drawable.ic_oui_wallpaper_outline)
.setContentTitle(getString(R.string.wallpaper_service))
.setContentText(getString(R.string.noti_desc))
.setContentIntent(PendingIntent.getActivity(
WallpaperService.this,
0,
new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS).putExtra(Settings.EXTRA_APP_PACKAGE, getPackageName()).putExtra(Settings.EXTRA_CHANNEL_ID, "4000"),
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE))
.setVisibility(NotificationCompat.VISIBILITY_SECRET)
.build());
return START_STICKY;
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
Log.e("WallpaperService", "onConfigurationChanged");
if (uiMode != newConfig.uiMode) {
if (newConfig.uiMode == 17) {
wallpaperUtil.loadWallpaper(true, true);
wallpaperUtil.loadWallpaper(false, true);
} else if (newConfig.uiMode == 33) {
wallpaperUtil.loadWallpaper(true, false);
wallpaperUtil.loadWallpaper(false, false);
}
uiMode = newConfig.uiMode;
}
}

@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
Loading

0 comments on commit 967cb38

Please sign in to comment.