summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
-rw-r--r--app/src/main/res/drawable-anydpi/ic_action_video_library.xml11
-rw-r--r--app/src/main/res/drawable-hdpi/ic_action_video_library.pngbin0 -> 235 bytes
-rw-r--r--app/src/main/res/drawable-mdpi/ic_action_video_library.pngbin0 -> 183 bytes
-rw-r--r--app/src/main/res/drawable-xhdpi/ic_action_video_library.pngbin0 -> 280 bytes
-rw-r--r--app/src/main/res/drawable-xxhdpi/ic_action_video_library.pngbin0 -> 382 bytes
-rw-r--r--app/src/main/res/layout/activity_main.xml20
9 files changed, 83 insertions, 17 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);
diff --git a/app/src/main/res/drawable-anydpi/ic_action_video_library.xml b/app/src/main/res/drawable-anydpi/ic_action_video_library.xml
new file mode 100644
index 0000000..a09d352
--- /dev/null
+++ b/app/src/main/res/drawable-anydpi/ic_action_video_library.xml
@@ -0,0 +1,11 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24"
+ android:tint="#FFFFFF"
+ android:alpha="0.8">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M4,6L2,6v14c0,1.1 0.9,2 2,2h14v-2L4,20L4,6zM20,2L8,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM12,14.5v-9l6,4.5 -6,4.5z" />
+</vector>
diff --git a/app/src/main/res/drawable-hdpi/ic_action_video_library.png b/app/src/main/res/drawable-hdpi/ic_action_video_library.png
new file mode 100644
index 0000000..c4d2528
--- /dev/null
+++ b/app/src/main/res/drawable-hdpi/ic_action_video_library.png
Binary files differ
diff --git a/app/src/main/res/drawable-mdpi/ic_action_video_library.png b/app/src/main/res/drawable-mdpi/ic_action_video_library.png
new file mode 100644
index 0000000..88b3ca9
--- /dev/null
+++ b/app/src/main/res/drawable-mdpi/ic_action_video_library.png
Binary files differ
diff --git a/app/src/main/res/drawable-xhdpi/ic_action_video_library.png b/app/src/main/res/drawable-xhdpi/ic_action_video_library.png
new file mode 100644
index 0000000..e78cbdf
--- /dev/null
+++ b/app/src/main/res/drawable-xhdpi/ic_action_video_library.png
Binary files differ
diff --git a/app/src/main/res/drawable-xxhdpi/ic_action_video_library.png b/app/src/main/res/drawable-xxhdpi/ic_action_video_library.png
new file mode 100644
index 0000000..76e0715
--- /dev/null
+++ b/app/src/main/res/drawable-xxhdpi/ic_action_video_library.png
Binary files differ
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 4521d0a..3081e15 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -32,13 +32,27 @@
</com.google.android.material.appbar.AppBarLayout>
- <com.google.android.material.floatingactionbutton.FloatingActionButton
- android:id="@+id/set_wallpaper"
+ <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
- app:srcCompat="@drawable/ic_action_wallpaper" />
+ android:orientation="vertical">
+
+ <com.google.android.material.floatingactionbutton.FloatingActionButton
+ android:id="@+id/set_file"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ app:srcCompat="@drawable/ic_action_video_library" />
+
+ <com.google.android.material.floatingactionbutton.FloatingActionButton
+ android:id="@+id/set_wallpaper"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="@dimen/fab_margin"
+ app:srcCompat="@drawable/ic_action_wallpaper" />
+ </LinearLayout>
+
</FrameLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout> \ No newline at end of file