Skip to content

Commit

Permalink
Add lockscreen Depth Wallpaper feature (Closes #230, closes #274)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmud0808 committed Sep 20, 2023
1 parent 1b5ad6f commit 47eba6f
Show file tree
Hide file tree
Showing 15 changed files with 640 additions and 181 deletions.
20 changes: 12 additions & 8 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
android:supportsRtl="true"
android:theme="@style/Theme.Iconify"
tools:targetApi="tiramisu">
<activity
android:name=".ui.activities.XposedDepthWallpaper"
android:exported="false" />
<activity
android:name=".ui.activities.XposedThemes"
android:exported="false" />
Expand Down Expand Up @@ -179,27 +182,28 @@

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> <!-- Custom App Icons -->
</activity>

<activity-alias
android:name=".SplashActivityRetro"
android:name=".SplashActivityThemed"
android:enabled="false"
android:exported="true"
android:icon="@mipmap/ic_launcher_retro"
android:roundIcon="@mipmap/ic_launcher_round_retro"
android:icon="@mipmap/ic_launcher_themed"
android:roundIcon="@mipmap/ic_launcher_round_themed"
android:targetActivity=".SplashActivity"
android:theme="@style/Theme.Iconify.SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
</activity-alias> <!-- Custom App Icons -->
<activity-alias
android:name=".SplashActivityThemed"
android:name=".SplashActivityRetro"
android:enabled="false"
android:exported="true"
android:icon="@mipmap/ic_launcher_themed"
android:roundIcon="@mipmap/ic_launcher_round_themed"
android:icon="@mipmap/ic_launcher_retro"
android:roundIcon="@mipmap/ic_launcher_round_retro"
android:targetActivity=".SplashActivity"
android:theme="@style/Theme.Iconify.SplashScreen">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public class Preferences {
public static final String HEADER_CLOCK_FONT_TEXT_SCALING = "xposed_headerclocktextscaling";
public static final String QSPANEL_HIDE_CARRIER = "xposed_qspanelhidecarrier";
public static final String LSCLOCK_SWITCH = "xposed_lockscreenclock";
public static final String LSCLOCK_AUTOHIDE = "xposed_lockscreenclockautohide";
public static final String LSCLOCK_STYLE = "xposed_lockscreenclockstyle";
public static final String LSCLOCK_TOPMARGIN = "xposed_lockscreenclocktopmargin";
public static final String LSCLOCK_BOTTOMMARGIN = "xposed_lockscreenclockbottommargin";
Expand All @@ -60,7 +59,8 @@ public class Preferences {
public static final String CUSTOM_BATTERY_HEIGHT = "xposed_custombatteryheight";
public static final String CUSTOM_BATTERY_MARGIN = "xposed_custombatterymargin";
public static final String HEADER_QQS_TOPMARGIN = "qqspanelTopMargin";
public static final String HIDE_DATA_DISABLED_ICON = "hideDataDisabledIcon";
public static final String HIDE_DATA_DISABLED_ICON = "xposed_hideDataDisabledIcon";
public static final String DEPTH_WALLPAPER_SWITCH = "xposed_depthwallpaper";

// Battery styles
public static final int BATTERY_STYLE_DEFAULT = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class Resources {
public static final String LSCLOCK_FONT_DIR = XPOSED_RESOURCE_TEMP_DIR + "/lsclock_font.ttf";
public static final String HEADER_CLOCK_FONT_DIR = XPOSED_RESOURCE_TEMP_DIR + "/headerclock_font.ttf";
public static final String HEADER_IMAGE_DIR = XPOSED_RESOURCE_TEMP_DIR + "/header_image.png";
public static final String DEPTH_WALL_FG_DIR = XPOSED_RESOURCE_TEMP_DIR + "/depth_wallpaper_fg.png";
public static final String DEPTH_WALL_BG_DIR = XPOSED_RESOURCE_TEMP_DIR + "/depth_wallpaper_bg.png";

// Overlays
public static final String QSC_overlay = "IconifyComponentQSC.overlay";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package com.drdisagree.iconify.ui.activities;

import static com.drdisagree.iconify.common.Const.SWITCH_ANIMATION_DELAY;
import static com.drdisagree.iconify.common.Preferences.DEPTH_WALLPAPER_SWITCH;
import static com.drdisagree.iconify.common.Resources.DEPTH_WALL_BG_DIR;
import static com.drdisagree.iconify.common.Resources.DEPTH_WALL_FG_DIR;
import static com.drdisagree.iconify.utils.FileUtil.copyToIconifyHiddenDir;
import static com.drdisagree.iconify.utils.FileUtil.getRealPath;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.widget.Toast;

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;

import com.drdisagree.iconify.R;
import com.drdisagree.iconify.config.RPrefs;
import com.drdisagree.iconify.databinding.ActivityXposedDepthWallpaperBinding;
import com.drdisagree.iconify.ui.utils.ViewHelper;
import com.drdisagree.iconify.utils.SystemUtil;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

public class XposedDepthWallpaper extends BaseActivity {

private ActivityXposedDepthWallpaperBinding binding;
ActivityResultLauncher<Intent> intentForegroundImage = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
if (result.getResultCode() == Activity.RESULT_OK) {
Intent data = result.getData();
String path = getRealPath(data);

if (path != null && copyToIconifyHiddenDir(path, DEPTH_WALL_FG_DIR)) {
RPrefs.putBoolean(DEPTH_WALLPAPER_SWITCH, !binding.enableDepthWallpaper.isChecked());
RPrefs.putBoolean(DEPTH_WALLPAPER_SWITCH, binding.enableDepthWallpaper.isChecked());
Toast.makeText(getApplicationContext(), getString(R.string.toast_selected_successfully), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), getResources().getString(R.string.toast_rename_file), Toast.LENGTH_SHORT).show();
}
}
});
ActivityResultLauncher<Intent> intentBackgroundImage = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
result -> {
if (result.getResultCode() == Activity.RESULT_OK) {
Intent data = result.getData();
String path = getRealPath(data);

if (path != null && copyToIconifyHiddenDir(path, DEPTH_WALL_BG_DIR)) {
RPrefs.putBoolean(DEPTH_WALLPAPER_SWITCH, !binding.enableDepthWallpaper.isChecked());
RPrefs.putBoolean(DEPTH_WALLPAPER_SWITCH, binding.enableDepthWallpaper.isChecked());
Toast.makeText(getApplicationContext(), getString(R.string.toast_selected_successfully), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), getResources().getString(R.string.toast_rename_file), Toast.LENGTH_SHORT).show();
}
}
});

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityXposedDepthWallpaperBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

// Header
ViewHelper.setHeader(this, binding.header.toolbar, R.string.activity_title_depth_wallpaper);

// Alert dialog
new MaterialAlertDialogBuilder(this, R.style.MaterialComponents_MaterialAlertDialog)
.setTitle(getString(R.string.attention))
.setMessage(getString(R.string.depth_wallpaper_alert_msg))
.setPositiveButton(getString(R.string.understood), (dialog, which) -> dialog.dismiss())
.setCancelable(true)
.show();

// Enable depth wallpaper
binding.enableDepthWallpaper.setChecked(RPrefs.getBoolean(DEPTH_WALLPAPER_SWITCH, false));
binding.enableDepthWallpaper.setOnCheckedChangeListener((buttonView, isChecked) -> {
RPrefs.putBoolean(DEPTH_WALLPAPER_SWITCH, isChecked);
binding.pickForegroundImg.setEnabled(isChecked);
binding.pickBackgroundImg.setEnabled(isChecked);
new Handler(Looper.getMainLooper()).postDelayed(SystemUtil::handleSystemUIRestart, SWITCH_ANIMATION_DELAY);
});
binding.enableDepthWallpaperContainer.setOnClickListener(v -> binding.enableDepthWallpaper.toggle());

// Foreground image
binding.pickForegroundImg.setEnabled(binding.enableDepthWallpaper.isChecked());
binding.pickForegroundImg.setOnClickListener(v -> {
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(this);
} else {
browseForegroundImage();
}
});

// Background image
binding.pickBackgroundImg.setEnabled(binding.enableDepthWallpaper.isChecked());
binding.pickBackgroundImg.setOnClickListener(v -> {
if (!SystemUtil.hasStoragePermission()) {
SystemUtil.requestStoragePermission(this);
} else {
browseBackgroundImage();
}
});
}

public void browseForegroundImage() {
Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
chooseFile.addCategory(Intent.CATEGORY_OPENABLE);
chooseFile.setType("image/*");
intentForegroundImage.launch(chooseFile);
}

public void browseBackgroundImage() {
Intent chooseFile = new Intent(Intent.ACTION_GET_CONTENT);
chooseFile.addCategory(Intent.CATEGORY_OPENABLE);
chooseFile.setType("image/*");
intentBackgroundImage.launch(chooseFile);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.drdisagree.iconify.ui.activities;

import static com.drdisagree.iconify.common.Const.SWITCH_ANIMATION_DELAY;
import static com.drdisagree.iconify.common.Preferences.LSCLOCK_AUTOHIDE;
import static com.drdisagree.iconify.common.Preferences.LSCLOCK_BOTTOMMARGIN;
import static com.drdisagree.iconify.common.Preferences.LSCLOCK_COLOR_CODE;
import static com.drdisagree.iconify.common.Preferences.LSCLOCK_COLOR_SWITCH;
Expand Down Expand Up @@ -86,14 +85,6 @@ protected void onCreate(Bundle savedInstanceState) {
});
binding.enableLockscreenClockContainer.setOnClickListener(v -> binding.enableLockscreenClock.toggle());

// Auto hide clock
binding.enableAutoHideClock.setChecked(RPrefs.getBoolean(LSCLOCK_AUTOHIDE, false));
binding.enableAutoHideClock.setOnCheckedChangeListener((buttonView, isChecked) -> {
RPrefs.putBoolean(LSCLOCK_AUTOHIDE, isChecked);
new Handler(Looper.getMainLooper()).postDelayed(SystemUtil::handleSystemUIRestart, SWITCH_ANIMATION_DELAY);
});
binding.autoHideClockContainer.setOnClickListener(v -> binding.enableAutoHideClock.toggle());

// Lockscreen clock style
binding.lockscreenClockPreview.setOrientation(ViewPager2.ORIENTATION_HORIZONTAL);
ClockPreviewAdapter adapter = initLockscreenClockStyles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.drdisagree.iconify.databinding.FragmentXposedMenuBinding;
import com.drdisagree.iconify.ui.activities.XposedBackgroundChip;
import com.drdisagree.iconify.ui.activities.XposedBatteryStyle;
import com.drdisagree.iconify.ui.activities.XposedDepthWallpaper;
import com.drdisagree.iconify.ui.activities.XposedHeaderClock;
import com.drdisagree.iconify.ui.activities.XposedHeaderImage;
import com.drdisagree.iconify.ui.activities.XposedLockscreenClock;
Expand Down Expand Up @@ -200,6 +201,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
xposed_menu.add(new Object[]{XposedHeaderImage.class, getResources().getString(R.string.activity_title_header_image), getResources().getString(R.string.activity_desc_header_image), R.drawable.ic_xposed_header_image});
xposed_menu.add(new Object[]{XposedHeaderClock.class, getResources().getString(R.string.activity_title_header_clock), getResources().getString(R.string.activity_desc_header_clock), R.drawable.ic_xposed_header_clock});
xposed_menu.add(new Object[]{XposedLockscreenClock.class, getResources().getString(R.string.activity_title_lockscreen_clock), getResources().getString(R.string.activity_desc_lockscreen_clock), R.drawable.ic_xposed_lockscreen});
xposed_menu.add(new Object[]{XposedDepthWallpaper.class, getResources().getString(R.string.activity_title_depth_wallpaper), getResources().getString(R.string.activity_desc_depth_wallpaper), R.drawable.ic_xposed_depth_wallpaper});
xposed_menu.add(new Object[]{XposedBackgroundChip.class, getResources().getString(R.string.activity_title_background_chip), getResources().getString(R.string.activity_desc_background_chip), R.drawable.ic_xposed_background_chip});
xposed_menu.add(new Object[]{XposedOthers.class, getResources().getString(R.string.activity_title_xposed_others), getResources().getString(R.string.activity_desc_xposed_others), R.drawable.ic_xposed_misc});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ public static LinearLayout initLockscreenClockStyle(Context mContext, int style)

final TextClock date8 = new TextClock(mContext);
ViewGroup.MarginLayoutParams dateParams8 = new ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.WRAP_CONTENT, ViewGroup.MarginLayoutParams.WRAP_CONTENT);
dateParams8.setMargins(0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 6 + lineHeight, mContext.getResources().getDisplayMetrics()), 0, 0);
dateParams8.setMargins(0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, lineHeight, mContext.getResources().getDisplayMetrics()), 0, 0);
date8.setLayoutParams(dateParams8);
date8.setFormat12Hour("MMMM dd");
date8.setFormat24Hour("MMMM dd");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.drdisagree.iconify.xposed.mods.BackgroundChip;
import com.drdisagree.iconify.xposed.mods.BatteryStyleManager;
import com.drdisagree.iconify.xposed.mods.DepthWallpaper;
import com.drdisagree.iconify.xposed.mods.HeaderClock;
import com.drdisagree.iconify.xposed.mods.HeaderImage;
import com.drdisagree.iconify.xposed.mods.HookCheck;
Expand Down Expand Up @@ -54,6 +55,7 @@ public static ArrayList<Class<? extends ModPack>> getEntries(String packageName)
modPacks.add(BackgroundChip.class);
modPacks.add(HeaderClock.class);
modPacks.add(HeaderImage.class);
modPacks.add(DepthWallpaper.class);
modPacks.add(LockscreenClock.class);
modPacks.add(Miscellaneous.class);
modPacks.add(QSBlackTheme.class);
Expand Down
Loading

0 comments on commit 47eba6f

Please sign in to comment.