summaryrefslogtreecommitdiff
path: root/app/src/main/java/com/javispedro/wallmotion/MainActivity.java
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2020-02-12 00:08:06 +0100
committerJavier <dev.git@javispedro.com>2020-02-12 20:48:39 +0100
commitac329e140435c3488ea5dfef89d237e2325da9e4 (patch)
tree47f03d0ae7ef63f9649aed834c0110b47e9936b5 /app/src/main/java/com/javispedro/wallmotion/MainActivity.java
downloadwallmotion-ac329e140435c3488ea5dfef89d237e2325da9e4.tar.gz
wallmotion-ac329e140435c3488ea5dfef89d237e2325da9e4.zip
initial import
Diffstat (limited to 'app/src/main/java/com/javispedro/wallmotion/MainActivity.java')
-rw-r--r--app/src/main/java/com/javispedro/wallmotion/MainActivity.java117
1 files changed, 117 insertions, 0 deletions
diff --git a/app/src/main/java/com/javispedro/wallmotion/MainActivity.java b/app/src/main/java/com/javispedro/wallmotion/MainActivity.java
new file mode 100644
index 0000000..c6859ae
--- /dev/null
+++ b/app/src/main/java/com/javispedro/wallmotion/MainActivity.java
@@ -0,0 +1,117 @@
+package com.javispedro.wallmotion;
+
+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.SurfaceHolder;
+import android.view.SurfaceView;
+import android.view.View;
+import android.view.Menu;
+import android.view.MenuItem;
+
+public class MainActivity extends AppCompatActivity {
+ private static final String TAG = "MainActivity";
+
+ private Renderer renderer;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_main);
+ Toolbar toolbar = findViewById(R.id.toolbar);
+ setSupportActionBar(toolbar);
+
+ FloatingActionButton fab = findViewById(R.id.set_wallpaper);
+ fab.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ openWallpaperSelector();
+ }
+ });
+
+ SurfaceView view = findViewById(R.id.wallpaper_view);
+ view.getHolder().addCallback(new WallpaperViewCallback());
+
+ renderer = new Renderer(this);
+ }
+
+ @Override
+ protected void onDestroy() {
+ renderer.stop();
+ renderer = null;
+
+ super.onDestroy();
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ // Inflate the menu; this adds items to the action bar if it is present.
+ getMenuInflater().inflate(R.menu.menu_main, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ // Handle action bar item clicks here. The action bar will
+ // automatically handle clicks on the Home/Up button, so long
+ // as you specify a parent activity in AndroidManifest.xml.
+ int id = item.getItemId();
+
+ if (id == R.id.action_settings) {
+ openSettingsActivity();
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ }
+
+ @Override
+ protected void onPause() {
+ renderer.stop();
+ super.onPause();
+ }
+
+ private class WallpaperViewCallback implements SurfaceHolder.Callback {
+ @Override
+ public void surfaceCreated(SurfaceHolder holder) {
+ Log.d(TAG, "surfaceCreated");
+ renderer.start(holder.getSurface());
+ }
+
+ @Override
+ public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
+
+ }
+
+ @Override
+ public void surfaceDestroyed(SurfaceHolder holder) {
+ Log.d(TAG, "surfaceDestroyed");
+ renderer.stop();
+ }
+ }
+
+ private void openSettingsActivity() {
+ Intent intent = new Intent(this, SettingsActivity.class);
+ startActivity(intent);
+ }
+
+ private void openWallpaperSelector() {
+ Intent intent = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
+ intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
+ new ComponentName(this, WallService.class));
+ startActivity(intent);
+ }
+}