-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function to inject wallpaper in home screen
- Loading branch information
Showing
11 changed files
with
357 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.wmods.wppenhacer; | ||
|
||
import android.net.Uri; | ||
import android.util.Log; | ||
|
||
import androidx.activity.result.ActivityResultLauncher; | ||
import androidx.activity.result.contract.ActivityResultContracts; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import com.wmods.wppenhacer.utils.RealPathUtil; | ||
|
||
import java.io.File; | ||
|
||
public class FilePicker { | ||
|
||
private static OnFilePickedListener mOnFilePickedListener; | ||
private static AppCompatActivity mActivity; | ||
public static ActivityResultLauncher<String> fileSalve; | ||
private static OnUriPickedListener mOnUriPickedListener; | ||
public static ActivityResultLauncher<String[]> fileCapture; | ||
|
||
public static void registerFilePicker(AppCompatActivity activity) { | ||
mActivity = activity; | ||
fileCapture = activity.registerForActivityResult(new ActivityResultContracts.OpenDocument(), FilePicker::setFile); | ||
fileSalve = activity.registerForActivityResult(new ActivityResultContracts.CreateDocument("*/*"), FilePicker::setFile); | ||
} | ||
|
||
private static void setFile(Uri uri) { | ||
if (uri == null) return; | ||
|
||
if (mOnFilePickedListener == null) { | ||
mOnUriPickedListener.onUriPicked(uri); | ||
mOnUriPickedListener = null; | ||
} | ||
|
||
if (mOnFilePickedListener != null) { | ||
var realPath = RealPathUtil.getRealFilePath(mActivity, uri); | ||
if (realPath == null) return; | ||
mOnFilePickedListener.onFilePicked(new File(realPath)); | ||
mOnFilePickedListener = null; | ||
} | ||
} | ||
|
||
|
||
|
||
public static void setOnFilePickedListener(OnFilePickedListener onFilePickedListener) { | ||
mOnFilePickedListener = onFilePickedListener; | ||
} | ||
|
||
public static void setOnUriPickedListener(OnUriPickedListener onFilePickedListener) { | ||
mOnUriPickedListener = onFilePickedListener; | ||
} | ||
|
||
public interface OnFilePickedListener { | ||
void onFilePicked(File file); | ||
} | ||
|
||
public interface OnUriPickedListener { | ||
void onUriPicked(Uri uri); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/src/main/java/com/wmods/wppenhacer/preference/FileSelectPreference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.wmods.wppenhacer.preference; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.util.Log; | ||
|
||
import androidx.activity.result.PickVisualMediaRequest; | ||
import androidx.activity.result.contract.ActivityResultContracts; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.preference.Preference; | ||
import androidx.preference.PreferenceManager; | ||
|
||
import com.wmods.wppenhacer.FilePicker; | ||
import com.wmods.wppenhacer.R; | ||
|
||
import java.io.File; | ||
import java.util.Arrays; | ||
|
||
public class FileSelectPreference extends Preference implements Preference.OnPreferenceClickListener, FilePicker.OnFilePickedListener { | ||
|
||
private String[] mineTypes; | ||
|
||
public FileSelectPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { | ||
super(context, attrs, defStyleAttr, defStyleRes); | ||
init(context,attrs); | ||
} | ||
|
||
public FileSelectPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
init(context,attrs); | ||
} | ||
|
||
public FileSelectPreference(@NonNull Context context, @Nullable AttributeSet attrs) { | ||
super(context, attrs); | ||
init(context,attrs); | ||
} | ||
|
||
public void init(Context context, AttributeSet attrs) { | ||
setOnPreferenceClickListener(this); | ||
var typedArray = context.getTheme().obtainStyledAttributes( | ||
attrs, R.styleable.FileSelectPreference, | ||
0, 0 | ||
); | ||
var attrsArray = typedArray.getTextArray(R.styleable.FileSelectPreference_android_entryValues); | ||
mineTypes = Arrays.stream(attrsArray).map(String::valueOf).toArray(String[]::new); | ||
var prefs = PreferenceManager.getDefaultSharedPreferences(context); | ||
var keyValue = prefs.getString(this.getKey(),null); | ||
setSummary(keyValue); | ||
} | ||
|
||
|
||
@Override | ||
public boolean onPreferenceClick(@NonNull Preference preference) { | ||
FilePicker.setOnFilePickedListener(this); | ||
FilePicker.fileCapture.launch(mineTypes); | ||
return false; | ||
} | ||
|
||
@Override | ||
public void onFilePicked(File file) { | ||
getSharedPreferences().edit().putString(getKey(),file.getAbsolutePath()).apply(); | ||
setSummary(file.getAbsolutePath()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
app/src/main/java/com/wmods/wppenhacer/views/WallpaperView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.wmods.wppenhacer.views; | ||
|
||
import static de.robv.android.xposed.XposedBridge.log; | ||
|
||
import android.content.Context; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapFactory; | ||
import android.graphics.drawable.BitmapDrawable; | ||
import android.graphics.drawable.Drawable; | ||
import android.view.View; | ||
import android.widget.FrameLayout; | ||
import android.widget.ImageView; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import java.io.File; | ||
|
||
import de.robv.android.xposed.XSharedPreferences; | ||
|
||
public class WallpaperView extends FrameLayout { | ||
private final XSharedPreferences prefs; | ||
private ImageView imageView; | ||
private float mAlpha = 1f; | ||
|
||
public WallpaperView(@NonNull Context context, XSharedPreferences preferences) { | ||
super(context); | ||
this.prefs = preferences; | ||
init(context); | ||
} | ||
|
||
private void init(Context context) { | ||
imageView = new android.widget.ImageView(context); | ||
imageView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); | ||
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); | ||
imageView.setAdjustViewBounds(false); | ||
try { | ||
Bitmap bitmap = BitmapFactory.decodeFile(prefs.getString("wallpaper_file", "")); | ||
Drawable drawable = new BitmapDrawable(getResources(), bitmap); | ||
imageView.setImageDrawable(drawable); | ||
this.mAlpha = (100 - prefs.getInt("wallpaper_alpha", 30)) / 100f; | ||
addView(imageView); | ||
}catch (Exception e){ | ||
log(e.toString()); | ||
} | ||
} | ||
|
||
@Override | ||
public void addView(View child) { | ||
if (child != imageView) | ||
child.setAlpha(mAlpha); | ||
super.addView(child); | ||
} | ||
} |
Oops, something went wrong.