more old stuff

This commit is contained in:
qvalentin 2021-04-23 12:05:21 +02:00
parent b7e46fd285
commit 5133746a99
11 changed files with 294 additions and 49 deletions

View File

@ -26,5 +26,10 @@
<option name="name" value="maven" />
<option name="url" value="https://jitpack.io" />
</remote-repository>
<remote-repository>
<option name="id" value="MavenRepo" />
<option name="name" value="MavenRepo" />
<option name="url" value="https://repo.maven.apache.org/maven2/" />
</remote-repository>
</component>
</project>

View File

@ -1,5 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>

View File

@ -34,10 +34,11 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support:palette-v7:29.0.0'
implementation 'org.jetbrains:annotations:19.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
compile 'com.crossbowffs.remotepreferences:remotepreferences:0.7'
implementation 'com.crossbowffs.remotepreferences:remotepreferences:0.7'
def libsuVersion = '3.0.2'
@ -53,12 +54,22 @@ dependencies {
// Optional: Bundle prebuilt BusyBox binaries
// implementation "com.github.topjohnwu.libsu:busybox:${libsuVersion}"
implementation 'com.jayway.jsonpath:json-path:2.4.0'
implementation 'com.pddstudio:earthview-android:1.2.0'
}
allprojects {
repositories {
google()
jcenter()
mavenCentral()
}
}
}

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.valentin.colorconsistency">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<application

View File

@ -2,13 +2,13 @@ package de.valentin.colorconsistency;
import android.app.IntentService;
import android.content.Intent;
import android.util.Log;
import androidx.annotation.Nullable;
import de.valentin.colorconsistency.ToGravityBox.GravitBoxConnector;
import de.valentin.colorconsistency.ToKWLP.KLWPConnector;
import de.valentin.colorconsistency.ToNova.NovaLauncherConnector;
import de.valentin.colorconsistency.ToSwiftkey.SwiftkeyConnector;
import de.valentin.colorconsistency.image.RandomImage;
import de.valentin.colorconsistency.image.SelectedColors;
import de.valentin.colorconsistency.image.*;
import java.io.File;
@ -29,9 +29,45 @@ public class ImageChangeService extends IntentService {
@Override
protected void onHandleIntent(@Nullable Intent intent) {
RandomImage randomImage = new RandomImage(new File("/storage/emulated/0/Pictures/Wallpapers"));
String imagePath= randomImage.getPath();
SelectedColors colors = randomImage.getSelectedColors();
// RedditImage redditImage=new RedditImage();
// String imagePath= redditImage.getImageURL();
String variant="earthview";
switch(variant){
case "local":{
RandomImage randomImage = new RandomImage(new File("/storage/emulated/0/Pictures/Wallpapers"));
applyChangedImage(randomImage);
}
break;
case "earthview":{
Earthview earthview=new Earthview(this);
}
break;
case "reddit":{
RedditImage redditImage=new RedditImage();
applyChangedImage(redditImage);
}
}
}
public void applyChangedImage( SelectedImage image){
Log.v("PATH",image.getPath());
Log.v("PATH","d"+String.valueOf(image.getSelectedColors().getBackground()));
SelectedColors colors = image.getSelectedColors();
// SelectedColors colors = new SelectedColors(300,300,300);
String imagePath = image.getPath();
sendBroadcast(new KLWPConnector(imagePath, colors).getIntent());
@ -47,5 +83,4 @@ public class ImageChangeService extends IntentService {
}

View File

@ -1,2 +1,51 @@
package de.valentin.colorconsistency.image;public class DownloadBitmap {
package de.valentin.colorconsistency.image;
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import com.topjohnwu.superuser.io.SuFileOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
public class DownloadBitmap extends AsyncTask<String, Bitmap,Bitmap> {
SelectedImage selectedImage;
File outputFile;
public DownloadBitmap(SelectedImage selectedImage, File outputFile) {
this.selectedImage=selectedImage;
this.outputFile=outputFile;
}
@Override
protected Bitmap doInBackground(String... urls) {
try {
return BitmapFactory.decodeStream(new URL(urls[0]).openStream());
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
@SuppressLint("WrongThread")
protected void onPostExecute(Bitmap bitmap) {
selectedImage.setBitmap(bitmap);
selectedImage.createPalette();
Earthview si=(Earthview)selectedImage;
try (OutputStream out = new FileOutputStream(outputFile)) {
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
}
catch (Exception e){
e.printStackTrace();
}
si.getImageChangeService().applyChangedImage(selectedImage);
}
}

View File

@ -1,2 +1,68 @@
package de.valentin.colorconsistency.image;public class Earthview {
package de.valentin.colorconsistency.image;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import androidx.annotation.Nullable;
import androidx.palette.graphics.Palette;
import com.pddstudio.earthview.EarthView;
import com.pddstudio.earthview.EarthWallpaper;
import com.pddstudio.earthview.SingleEarthViewCallback;
import de.valentin.colorconsistency.ImageChangeService;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
public class Earthview extends SelectedImage implements SingleEarthViewCallback {
ImageChangeService imageChangeService;
public ImageChangeService getImageChangeService() {
return imageChangeService;
}
public Earthview(ImageChangeService imageChangeService) {
this.imageChangeService=imageChangeService;
EarthView.withGoogle().getRandomEarthWallpaper(this);
}
@Override
public void onStartedLoading() {
}
@Override
public void onFinishedLoading(@Nullable @org.jetbrains.annotations.Nullable EarthWallpaper earthWallpaper) {
if(earthWallpaper != null) {
Log.v("IDEARTH",earthWallpaper.getWallpaperId());
selected=new File("sdcard/Pictures/Earthview/"+earthWallpaper.getWallpaperId()+".jpg");
path = selected.getAbsolutePath();
if (!selected.exists()) {
// bitmap = BitmapFactory.decodeStream(url.openStream());
new DownloadBitmap(this,selected).execute(earthWallpaper.getWallPhotoUrl());
}
else {
bitmap = BitmapFactory.decodeFile(path);
createPalette();
imageChangeService.applyChangedImage(this);
}
}
}
@Override
public void onCancelledLoading() {
}
}

View File

@ -8,13 +8,7 @@ import androidx.palette.graphics.Palette;
import java.io.File;
import java.util.Random;
public class RandomImage {
File folder;
File selected;
String path;
Bitmap bitmap;
Palette palette;
SelectedColors selectedColors;
public class RandomImage extends SelectedImage {
public RandomImage(File folder) {
@ -31,12 +25,7 @@ public class RandomImage {
path = selected.getAbsolutePath();
bitmap = BitmapFactory.decodeFile(path);
palette = Palette.from(bitmap).generate();
palette.getDarkMutedColor(0);
selectedColors = new SelectedColors(
palette.getLightMutedColor(Color.WHITE),
palette.getDarkMutedColor(Color.BLACK),
palette.getDominantColor(Color.WHITE));
createPalette();
}
catch (Exception e ){
path="error";
@ -45,27 +34,4 @@ public class RandomImage {
}
public String getPath() {
return path;
}
public File getFolder() {
return folder;
}
public File getSelected() {
return selected;
}
public Bitmap getBitmap() {
return bitmap;
}
public Palette getPalette() {
return palette;
}
public SelectedColors getSelectedColors() {
return selectedColors;
}
}

View File

@ -1,2 +1,60 @@
package de.valentin.colorconsistency.image;public class RedditImage {
package de.valentin.colorconsistency.image;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import android.util.Log;
import com.jayway.jsonpath.JsonPath;
public class RedditImage extends SelectedImage {
private String[] subreddits={"Art"};
String imageURL;
public RedditImage() {
getImageURLfromReddit();
}
void getImageURLfromReddit(){
try{
URL url = new URL("https://www.reddit.com/r/"+subreddits[0]+".json");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
StringBuilder stringBuilder=new StringBuilder();
String line;
while (reader.ready()){
line = reader.readLine();
Log.v("OUTPUT","d"+line);
stringBuilder.append(line);
}
Log.v("OUTPUT","d"+stringBuilder.toString());
Log.v("OUTPUT","hallo");
imageURL= JsonPath.read(stringBuilder, ".data.children[1].data.url");
Log.v("IMAGEURL",imageURL);
} catch(Exception e){
// In your production code handle any errors and catch the individual exceptions
e.printStackTrace();
}
}
public String getImageURL() {
return imageURL;
}
}

View File

@ -1,2 +1,51 @@
package de.valentin.colorconsistency.image;public class SelectedImage {
package de.valentin.colorconsistency.image;
import android.graphics.Bitmap;
import android.graphics.Color;
import androidx.palette.graphics.Palette;
import java.io.File;
public class SelectedImage {
File folder;
File selected;
String path;
Bitmap bitmap;
Palette palette;
SelectedColors selectedColors;
public void setBitmap(Bitmap bitmap) {
this.bitmap = bitmap;
}
void createPalette(){
palette = Palette.from(bitmap).generate();
palette.getDarkMutedColor(0);
selectedColors = new SelectedColors(
palette.getLightMutedColor(Color.WHITE),
palette.getDarkMutedColor(Color.BLACK),
palette.getDominantColor(Color.WHITE));
}
public File getSelected() {
return selected;
}
public String getPath() {
return path;
}
public Bitmap getBitmap() {
return bitmap;
}
public Palette getPalette() {
return palette;
}
public SelectedColors getSelectedColors() {
return selectedColors;
}
}

View File

@ -16,7 +16,9 @@ allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {