Skip to content

Commit

Permalink
Added Weather Custom Margins
Browse files Browse the repository at this point in the history
Fixed Fingerprint Icon Scaling
  • Loading branch information
DHD2280 committed Apr 22, 2024
1 parent f654e96 commit c75fa05
Show file tree
Hide file tree
Showing 13 changed files with 187 additions and 57 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
applicationId = "it.dhd.oxygencustomizer"
minSdk = 33
targetSdk = 34
versionCode = 2
versionName = "1.0.1"
versionCode = 3
versionName = "1.0.3"
setProperty("archivesBaseName", "Oxygen Customizer v$versionName")
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -146,6 +146,8 @@ dependencies {
implementation("org.greenrobot:eventbus:3.3.1")

implementation("com.crossbowffs.remotepreferences:remotepreferences:0.8")

implementation("com.github.tiagohm.MarkdownView:library:0.19.0")
}

tasks.register("printVersionName") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
Expand Down Expand Up @@ -63,7 +64,7 @@ public class LockscreenWeather
Preference.OnPreferenceChangeListener {

private static final String DEFAULT_WEATHER_ICON_PACKAGE = "it.dhd.oxygencustomizer.google";
private SharedPreferences mPrefs = PreferenceHelper.instance.mPreferences;
private SharedPreferences mPrefs;
private ListPreference mProvider;
private SwitchPreferenceCompat mCustomLocation;
private ListPreference mUnits;
Expand Down Expand Up @@ -119,7 +120,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
public void onResume() {
super.onResume();
mWeatherClient.addObserver(this);
doLoadPreferences();
//doLoadPreferences();
// values can be changed from outside
if (mTriggerPermissionCheck) {
checkLocationPermissions(true);
Expand All @@ -128,6 +129,15 @@ public void onResume() {
queryAndUpdateWeather();
}

private boolean hasPermissions() {
return requireContext().checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED
&& requireContext().checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
== PackageManager.PERMISSION_GRANTED
&& requireContext().checkSelfPermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
== PackageManager.PERMISSION_GRANTED;
}

ActivityResultLauncher<Intent> mCustomLocationLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
result -> {
if (result.getResultCode() == Activity.RESULT_OK) {
Expand All @@ -145,11 +155,12 @@ public void onResume() {
});

private void checkLocationPermissions(boolean force) {
if (getContext().checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
Log.d("LockscreenWeather", "checking location permissions");
if (requireContext().checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED
|| getContext().checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
|| requireContext().checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
!= PackageManager.PERMISSION_GRANTED ||
getContext().checkSelfPermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
requireContext().checkSelfPermission(Manifest.permission.ACCESS_BACKGROUND_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissionLauncher.launch(new String[]{
Manifest.permission.ACCESS_FINE_LOCATION,
Expand Down Expand Up @@ -205,6 +216,20 @@ private void showDialog() {
dialog.show();
}

private void showPermissionDialog() {
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext());
builder.setTitle(R.string.weather_permission_dialog_title);
builder.setMessage(R.string.weather_permission_dialog_message);
builder.setCancelable(false);
builder.setPositiveButton(android.R.string.ok, (dialog, which) -> {
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", BuildConfig.APPLICATION_ID, null);
intent.setData(uri);
startActivity(intent);
});
builder.show();
}

private void disableService() {
// stop any pending
WeatherUpdateService.cancelAllUpdate(getContext());
Expand All @@ -222,6 +247,14 @@ public void onPause() {

public void doLoadPreferences() {

if (mPrefs == null) {
if (PreferenceHelper.instance != null) {
mPrefs = PreferenceHelper.instance.mPreferences;
} else {
mPrefs = getContext().createDeviceProtectedStorageContext().getSharedPreferences(BuildConfig.APPLICATION_ID + "_preferences", Context.MODE_PRIVATE);
}
}

final PreferenceScreen prefScreen = getPreferenceScreen();
mEnable = findPreference(LOCKSCREEN_WEATHER_SWITCH);
if (mEnable != null) {
Expand Down Expand Up @@ -405,6 +438,9 @@ public boolean onPreferenceChange(@NonNull Preference preference, Object newValu
if (preference == mEnable) {
Config.setEnabled(getContext(), (Boolean) newValue);
if ((Boolean) newValue) {
if (!hasPermissions()) {
showPermissionDialog();
}
enableService();
if (!mCustomLocation.isChecked()) {
checkLocationEnabledInitial();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ public static class LockscreenWeather {
public static final String LOCKSCREEN_WEATHER_WIND = "weather_show_wind";
public static final String LOCKSCREEN_WEATHER_CUSTOM_COLOR_SWITCH = "weather_custom_color_switch";
public static final String LOCKSCREEN_WEATHER_CUSTOM_COLOR = "weather_custom_color";
public static final String LOCKSCREEN_WEATHER_CUSTOM_MARGINS = "weather_custom_margins";
public static final String LOCKSCREEN_WEATHER_CUSTOM_MARGIN_LEFT = "weather_margin_left";
public static final String LOCKSCREEN_WEATHER_CUSTOM_MARGIN_TOP = "weather_margin_top";

public static final String[] LOCKSCREEN_WEATHER_PREFS = {
LOCKSCREEN_WEATHER_SWITCH,
Expand All @@ -449,6 +452,12 @@ public static class LockscreenWeather {
LOCKSCREEN_WEATHER_CUSTOM_COLOR
};

public static final String[] LOCKSCREEN_WEATHER_MARGINS = {
LOCKSCREEN_WEATHER_CUSTOM_MARGINS,
LOCKSCREEN_WEATHER_CUSTOM_MARGIN_LEFT,
LOCKSCREEN_WEATHER_CUSTOM_MARGIN_TOP
};

}

public static final class SoundPrefs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_CUSTOM_COLOR;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_CUSTOM_COLOR_SWITCH;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_CUSTOM_LOCATION;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_CUSTOM_MARGINS;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_CUSTOM_MARGIN_LEFT;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_CUSTOM_MARGIN_TOP;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_HUMIDITY;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_ICON_PACK;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_IMAGE_SIZE;
Expand Down Expand Up @@ -364,6 +367,10 @@ public static boolean isVisible(String key) {
return instance.mPreferences.getBoolean(LOCKSCREEN_WEATHER_SWITCH, false) &&
instance.mPreferences.getBoolean(LOCKSCREEN_WEATHER_CUSTOM_COLOR_SWITCH, false);
}
case LOCKSCREEN_WEATHER_CUSTOM_MARGIN_TOP,
LOCKSCREEN_WEATHER_CUSTOM_MARGIN_LEFT -> {
return instance.mPreferences.getBoolean(LOCKSCREEN_WEATHER_CUSTOM_MARGINS, false);
}

// Volume Panel Customization
case "volume_panel_seekbar_link_primary" -> {
Expand Down Expand Up @@ -545,6 +552,8 @@ public static String getSummary(Context fragmentCompat, @NonNull String key) {
// Lockscreen Weather
case LOCKSCREEN_WEATHER_IMAGE_SIZE -> instance.mPreferences.getSliderInt(LOCKSCREEN_WEATHER_IMAGE_SIZE, 18) + "dp";
case LOCKSCREEN_WEATHER_TEXT_SIZE -> instance.mPreferences.getSliderInt(LOCKSCREEN_WEATHER_TEXT_SIZE, 16) + "sp";
case LOCKSCREEN_WEATHER_CUSTOM_MARGIN_TOP -> instance.mPreferences.getSliderInt(LOCKSCREEN_WEATHER_CUSTOM_MARGIN_TOP, 0) + "dp";
case LOCKSCREEN_WEATHER_CUSTOM_MARGIN_LEFT -> instance.mPreferences.getSliderInt(LOCKSCREEN_WEATHER_CUSTOM_MARGIN_LEFT, 0) + "dp";

// Sound Prefs
case "volume_dialog_timeout" -> instance.mPreferences.getSliderInt("volume_dialog_timeout", 3) + " s";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.graphics.ImageDecoder;
import android.graphics.drawable.AnimatedImageDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Environment;

import androidx.core.content.res.ResourcesCompat;
Expand Down Expand Up @@ -49,6 +50,7 @@ public class Lockscreen extends XposedMods {
private int fingerprintStyle = 0;
private Object mFpIcon;
private float mFpScale = 1.0f;
private Drawable mFpDrawable = null;

public Lockscreen(Context context) {
super(context);
Expand All @@ -62,6 +64,15 @@ public void updatePrefs(String... Key) {
customFingerprint = Xprefs.getBoolean(LOCKSCREEN_CUSTOM_FINGERPRINT, false);
fingerprintStyle = Integer.parseInt(Xprefs.getString(LOCKSCREEN_FINGERPRINT_STYLE, "0"));
mFpScale = Xprefs.getSliderFloat(LOCKSCREEN_FINGERPRINT_SCALING, 1.0f);

if (Key.length > 0) {
if (Key[0].equals(LOCKSCREEN_FINGERPRINT_STYLE)
|| Key[0].equals(LOCKSCREEN_CUSTOM_FINGERPRINT)
|| Key[0].equals(LOCKSCREEN_HIDE_FINGERPRINT)
|| Key[0].equals(LOCKSCREEN_FINGERPRINT_SCALING)) {
updateDrawable();
}
}
}

private boolean isMethodSecure() {
Expand Down Expand Up @@ -149,38 +160,42 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
private void updateFingerprintIcon(XC_MethodHook.MethodHookParam param, boolean isStartMethod) {
if (mFpIcon == null) mFpIcon = getObjectField(param.thisObject, "mFpIcon");

log(TAG + "updateFingerprintIcon");
AtomicReference<Drawable> d = new AtomicReference<>(null);
if (BuildConfig.DEBUG) log(TAG + "updateFingerprintIcon");

if (mFpDrawable == null) {
setObjectField(param.thisObject, "mFadeInAnimDrawable", null);
setObjectField(param.thisObject, "mFadeOutAnimDrawable", null);
}
setObjectField(param.thisObject, "mImMobileDrawable", mFpDrawable);
if (mFpIcon != null) {
callMethod(mFpIcon, "setImageDrawable", mFpDrawable == null ? null : mFpDrawable);
}
if (hideFingerprint && isStartMethod) {
param.setResult(null);
}
//if (!isStartMethod) callMethod(param.thisObject, "updateFpIconColor");
}

private void updateDrawable() {
if (customFingerprint) {
if (fingerprintStyle != -1) {
@SuppressLint("DiscouragedApi") int resId = ResourceManager.modRes.getIdentifier("fingerprint_" + fingerprintStyle,"drawable", BuildConfig.APPLICATION_ID);
d.set(ResourcesCompat.getDrawable(ResourceManager.modRes,
mFpDrawable = (ResourcesCompat.getDrawable(ResourceManager.modRes,
resId,
mContext.getTheme()));
} else {
try {
ImageDecoder.Source source = ImageDecoder.createSource(new File(Environment.getExternalStorageDirectory() + "/.oxygen_customizer/lockscreen_fp_icon.png"));
d.set(ImageDecoder.decodeDrawable(source));
if (d.get() instanceof AnimatedImageDrawable) {
((AnimatedImageDrawable) d.get()).setRepeatCount(AnimatedImageDrawable.REPEAT_INFINITE);
((AnimatedImageDrawable) d.get()).start();
mFpDrawable = ImageDecoder.decodeDrawable(source);
if (mFpDrawable instanceof AnimatedImageDrawable) {
((AnimatedImageDrawable) mFpDrawable).setRepeatCount(AnimatedImageDrawable.REPEAT_INFINITE);
((AnimatedImageDrawable) mFpDrawable).start();
}
} catch (Throwable ignored) {}
}
} else {
mFpDrawable = null;
}
if (d.get() == null) {
setObjectField(param.thisObject, "mFadeInAnimDrawable", null);
setObjectField(param.thisObject, "mFadeOutAnimDrawable", null);
}
//Drawable scaled = (Drawable) scaleDrawable(mContext, d.get(), mFpScale);
setObjectField(param.thisObject, "mImMobileDrawable", d.get());
if (mFpIcon != null) {
callMethod(mFpIcon, "setImageDrawable", d.get() == null ? null : d.get());
}
if (hideFingerprint && isStartMethod) {
param.setResult(null);
}
//if (!isStartMethod) callMethod(param.thisObject, "updateFpIconColor");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
import static it.dhd.oxygencustomizer.utils.Constants.LOCKSCREEN_CLOCK_LAYOUT;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_CUSTOM_COLOR;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_CUSTOM_COLOR_SWITCH;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_CUSTOM_MARGINS;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_CUSTOM_MARGIN_LEFT;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_CUSTOM_MARGIN_TOP;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_HUMIDITY;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_IMAGE_SIZE;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_MARGINS;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_PREFS;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_SHOW_CONDITION;
import static it.dhd.oxygencustomizer.utils.Constants.LockscreenWeather.LOCKSCREEN_WEATHER_SHOW_LOCATION;
Expand Down Expand Up @@ -41,6 +45,7 @@
import static it.dhd.oxygencustomizer.xposed.hooks.systemui.OpUtils.getPrimaryColor;
import static it.dhd.oxygencustomizer.xposed.utils.ViewHelper.dp2px;
import static it.dhd.oxygencustomizer.xposed.utils.ViewHelper.loadLottieAnimationView;
import static it.dhd.oxygencustomizer.xposed.utils.ViewHelper.setMargins;

import android.annotation.SuppressLint;
import android.app.ActivityManager;
Expand Down Expand Up @@ -69,6 +74,7 @@
import android.text.SpannableString;
import android.text.format.DateFormat;
import android.text.style.ForegroundColorSpan;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -135,6 +141,8 @@ public class LockscreenClock extends XposedMods {
private boolean weatherCustomColor = false;
private int weatherColor = Color.WHITE;
private int weatherStartPadding = 0, weatherTextSize = 16, weatherImageSize = 18;
private boolean mCustomMargins = false;
private int mLeftMargin = 0, mTopMargin = 0;

private final BroadcastReceiver mBatteryReceiver = new BroadcastReceiver() {
@Override
Expand Down Expand Up @@ -203,6 +211,9 @@ public void updatePrefs(String... Key) {
weatherShowWind = Xprefs.getBoolean(LOCKSCREEN_WEATHER_WIND, true);
weatherCustomColor = Xprefs.getBoolean(LOCKSCREEN_WEATHER_CUSTOM_COLOR_SWITCH, false);
weatherColor = Xprefs.getInt(LOCKSCREEN_WEATHER_CUSTOM_COLOR, Color.WHITE);
mCustomMargins = Xprefs.getBoolean(LOCKSCREEN_WEATHER_CUSTOM_MARGINS, false);
mLeftMargin = Xprefs.getSliderInt(LOCKSCREEN_WEATHER_CUSTOM_MARGIN_LEFT, 0);
mTopMargin = Xprefs.getSliderInt(LOCKSCREEN_WEATHER_CUSTOM_MARGIN_TOP, 0);

if (Key.length > 0) {
for(String LCPrefs : LOCKSCREEN_CLOCK_PREFS) {
Expand All @@ -217,6 +228,9 @@ public void updatePrefs(String... Key) {
for(String LCWeatherPref : LOCKSCREEN_WEATHER_PREFS) {
if (Key[0].equals(LCWeatherPref)) updateWeatherView();
}
for(String LCWeatherMargins : LOCKSCREEN_WEATHER_MARGINS) {
if (Key[0].equals(LCWeatherMargins)) updateMargins(CurrentWeatherView.getInstance());
}
}
}

Expand All @@ -243,7 +257,6 @@ protected void afterHookedMethod(MethodHookParam param) {

mClockView = KeyguardStatusView.findViewById(mContext.getResources().getIdentifier("keyguard_clock_container", "id", mContext.getPackageName()));


mMediaHostContainer = (View) getObjectField(param.thisObject, "mMediaHostContainer");


Expand Down Expand Up @@ -466,7 +479,7 @@ private void modifyClockView(View clockView) {
typeface = Typeface.createFromFile(new File(customFont));
}

ViewHelper.setMargins(clockView, mContext, 0, topMargin, 0, bottomMargin);
setMargins(clockView, mContext, 0, topMargin, 0, bottomMargin);

ViewHelper.findViewWithTagAndChangeColor(clockView, "accent1", customColor ? accent1 : systemAccent);
ViewHelper.findViewWithTagAndChangeColor(clockView, "accent2", customColor ? accent2 : systemAccent);
Expand Down Expand Up @@ -668,13 +681,23 @@ private void placeWeatherView() {
((ViewGroup) currentWeatherView.getParent()).removeView(currentWeatherView);
} catch (Throwable ignored) {
}
currentWeatherView.setPadding(weatherStartPadding, 0, 0, 0);
mClockViewContainer.addView(currentWeatherView);
refreshWeatherView(currentWeatherView);
updateMargins(currentWeatherView);
} catch (Throwable ignored) {
}
}

private void updateMargins(CurrentWeatherView weatherView) {
if (weatherView == null) return;
if (mCustomMargins) {
weatherView.setPadding(dp2px(mContext, mLeftMargin), dp2px(mContext, mTopMargin), 0, 0);
} else {
weatherView.setPadding(weatherStartPadding, 0, 0, 0);
}

}

private void refreshWeatherView(CurrentWeatherView currentWeatherView) {
if (currentWeatherView == null) return;
CurrentWeatherView.updateSizes(weatherTextSize, weatherImageSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
progress.setProgress(0);
progress.setVisibility(View.GONE);
} else {
batteryPercentOutView.setVisibility(View.VISIBLE);
if (customizePercSize) {
batteryPercentOutView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mBatteryPercSize);
}
Expand Down
Loading

0 comments on commit c75fa05

Please sign in to comment.