summaryrefslogtreecommitdiff
path: root/app/src/main/java/com/javispedro/wallmotion
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/com/javispedro/wallmotion')
-rw-r--r--app/src/main/java/com/javispedro/wallmotion/MainActivity.java29
-rw-r--r--app/src/main/java/com/javispedro/wallmotion/Renderer.java1
-rw-r--r--app/src/main/java/com/javispedro/wallmotion/SettingsActivity.java39
3 files changed, 55 insertions, 14 deletions
diff --git a/app/src/main/java/com/javispedro/wallmotion/MainActivity.java b/app/src/main/java/com/javispedro/wallmotion/MainActivity.java
index c6859ae..6e90228 100644
--- a/app/src/main/java/com/javispedro/wallmotion/MainActivity.java
+++ b/app/src/main/java/com/javispedro/wallmotion/MainActivity.java
@@ -4,18 +4,17 @@ import android.app.WallpaperManager;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
-
-import com.google.android.material.floatingactionbutton.FloatingActionButton;
-
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.appcompat.widget.Toolbar;
-
import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
-import android.view.Menu;
-import android.view.MenuItem;
+
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.appcompat.widget.Toolbar;
+
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
@@ -37,6 +36,14 @@ public class MainActivity extends AppCompatActivity {
}
});
+ fab = findViewById(R.id.set_file);
+ fab.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ openVideoFileSelector();
+ }
+ });
+
SurfaceView view = findViewById(R.id.wallpaper_view);
view.getHolder().addCallback(new WallpaperViewCallback());
@@ -108,6 +115,12 @@ public class MainActivity extends AppCompatActivity {
startActivity(intent);
}
+ private void openVideoFileSelector() {
+ Intent intent = new Intent(this, SettingsActivity.class);
+ intent.setAction(SettingsActivity.ACTION_CHOOSE_FILE);
+ startActivity(intent);
+ }
+
private void openWallpaperSelector() {
Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
diff --git a/app/src/main/java/com/javispedro/wallmotion/Renderer.java b/app/src/main/java/com/javispedro/wallmotion/Renderer.java
index efcd7c5..2420277 100644
--- a/app/src/main/java/com/javispedro/wallmotion/Renderer.java
+++ b/app/src/main/java/com/javispedro/wallmotion/Renderer.java
@@ -129,6 +129,7 @@ public class Renderer extends ContextWrapper {
player.setOnSeekCompleteListener(listener);
player.setLooping(true);
player.setVolume(0, 0);
+ player.setAudioSessionId(0);
player.setSurface(surface);
Log.d(TAG, "setting data source to " + uri.toString());
player.setDataSource(this, uri);
diff --git a/app/src/main/java/com/javispedro/wallmotion/SettingsActivity.java b/app/src/main/java/com/javispedro/wallmotion/SettingsActivity.java
index 6919ea1..5fee7df 100644
--- a/app/src/main/java/com/javispedro/wallmotion/SettingsActivity.java
+++ b/app/src/main/java/com/javispedro/wallmotion/SettingsActivity.java
@@ -20,14 +20,19 @@ import androidx.preference.PreferenceManager;
public class SettingsActivity extends AppCompatActivity {
private static final String TAG = "SettingsActivity";
+ public static final String ACTION_CHOOSE_FILE = "com.javispedro.wallmotion.choose_file";
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
+
+ SettingsFragment fragment = new SettingsFragment();
getSupportFragmentManager()
.beginTransaction()
- .replace(R.id.settings, new SettingsFragment())
+ .replace(R.id.settings, fragment)
.commit();
+
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
@@ -41,6 +46,8 @@ public class SettingsActivity extends AppCompatActivity {
}
public static class SettingsFragment extends PreferenceFragmentCompat {
+ private static final String TAG = "SettingsFragment";
+
private final static int PICK_VIDEO_FILE = 1;
@Override
@@ -50,11 +57,7 @@ public class SettingsActivity extends AppCompatActivity {
video_file.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
- Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
- intent.addCategory(Intent.CATEGORY_OPENABLE);
- intent.setType("video/*");
- intent.setFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
- startActivityForResult(intent, PICK_VIDEO_FILE);
+ openVideoFilePicker();
return true;
}
});
@@ -70,6 +73,16 @@ public class SettingsActivity extends AppCompatActivity {
}
@Override
+ public void onStart() {
+ super.onStart();
+ Intent launchIntent = getActivity().getIntent();
+ if (launchIntent != null && launchIntent.getAction().equals(ACTION_CHOOSE_FILE)) {
+ openVideoFilePicker();
+ getActivity().finish();
+ }
+ }
+
+ @Override
public void onActivityResult(int requestCode, int resultCode,
Intent resultData) {
switch (requestCode) {
@@ -82,6 +95,14 @@ public class SettingsActivity extends AppCompatActivity {
}
}
+ private void openVideoFilePicker() {
+ Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
+ intent.addCategory(Intent.CATEGORY_OPENABLE);
+ intent.setType("video/*");
+ intent.setFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
+ startActivityForResult(intent, PICK_VIDEO_FILE);
+ }
+
private void setVideoFile(Uri uri) {
ContentResolver resolver = getContext().getContentResolver();
@@ -89,6 +110,12 @@ public class SettingsActivity extends AppCompatActivity {
String cur_value = getStringPref(getString(R.string.settings_video_file_key));
if (!TextUtils.isEmpty(cur_value)) {
Uri cur_uri = Uri.parse(cur_value);
+
+ if (cur_uri.equals(uri)) {
+ Log.d(TAG, "identical uri selected");
+ return;
+ }
+
Log.d(TAG, "release persistable uri permission on uri: " + cur_uri.toString());
try {
resolver.releasePersistableUriPermission(cur_uri, Intent.FLAG_GRANT_READ_URI_PERMISSION);