diff --git a/MyFirstSlideshow/app/build.gradle b/MyFirstSlideshow/app/build.gradle index 1a1ed18..54b2060 100644 --- a/MyFirstSlideshow/app/build.gradle +++ b/MyFirstSlideshow/app/build.gradle @@ -20,4 +20,5 @@ android { dependencies { compile 'com.android.support:appcompat-v7:25.3.1' + compile 'com.karumi:dexter:4.1.0' } diff --git a/MyFirstSlideshow/app/src/main/AndroidManifest.xml b/MyFirstSlideshow/app/src/main/AndroidManifest.xml index c10f24d..c01aa4e 100644 --- a/MyFirstSlideshow/app/src/main/AndroidManifest.xml +++ b/MyFirstSlideshow/app/src/main/AndroidManifest.xml @@ -2,6 +2,12 @@ + + + + + + image1; + volatile WeakReference image2; + + static View[] dots1; + static View[] dots2; @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + + if (savedInstanceState == null) { + dots1 = new View[4]; + dots1[0] = getWindow().findViewById(R.id.dots1dot1); + dots1[1] = getWindow().findViewById(R.id.dots1dot2); + dots1[2] = getWindow().findViewById(R.id.dots1dot3); + dots1[3] = getWindow().findViewById(R.id.dots1dot4); + dots2 = new View[4]; + dots2[0] = getWindow().findViewById(R.id.dots2dot1); + dots2[1] = getWindow().findViewById(R.id.dots2dot2); + dots2[2] = getWindow().findViewById(R.id.dots2dot3); + dots2[3] = getWindow().findViewById(R.id.dots2dot4); + } + + super.onCreate(savedInstanceState); + + image1 = new WeakReference((ImageView) getWindow().findViewById(R.id.image1)); + image2 = new WeakReference((ImageView) getWindow().findViewById(R.id.image2)); + } + + public synchronized void onButtonOneClicked(View button) { + String currentImage = "" + images.get(i % 4); + i += 1; + // the last url of the array changes every ~ 15 minutes + Bitmap b; + try { + URL url = new URL(currentImage); + URLConnection c = url.openConnection(); + b = BitmapFactory.decodeStream(c.getInputStream()); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Error decoding picture"); + } + + image1.get().setImageBitmap(b); + + //Update dots + if (i % 4 == 0) { + dots1[0].setBackgroundColor(GREEN); + dots1[1].setBackgroundColor(GRAY); + dots1[2].setBackgroundColor(GRAY); + dots1[3].setBackgroundColor(GRAY); + } + if (i % 4 == 1) { + dots1[1].setBackgroundColor(GREEN); + dots1[0].setBackgroundColor(GRAY); + dots1[2].setBackgroundColor(GRAY); + dots1[3].setBackgroundColor(GRAY); + } + if (i % 4 == 2) { + dots1[2].setBackgroundColor(GREEN); + dots1[1].setBackgroundColor(GRAY); + dots1[0].setBackgroundColor(GRAY); + dots1[3].setBackgroundColor(GRAY); + } + if (i % 4 == 3) { + dots1[3].setBackgroundColor(GREEN); + dots1[1].setBackgroundColor(GRAY); + dots1[2].setBackgroundColor(GRAY); + dots1[0].setBackgroundColor(GRAY); + } + } + + public synchronized void onButtonTwoClicked(View button) { + String currentImage = "" + images.get(j % 4); + j += 1; + // the last url of the array changes every ~ 15 minutes + Bitmap b; + try { + URL url = new URL(currentImage); + URLConnection c = url.openConnection(); + b = BitmapFactory.decodeStream(c.getInputStream()); + } catch (Exception e) { + e.printStackTrace(); + throw new RuntimeException("Error decoding picture"); + } + + image2.get().setImageBitmap(b); + + //Update dots + if (j % 4 == 0) { + dots2[0].setBackgroundColor(GREEN); + dots2[1].setBackgroundColor(GRAY); + dots2[2].setBackgroundColor(GRAY); + dots2[3].setBackgroundColor(GRAY); + } + if (j % 4 == 1) { + dots2[1].setBackgroundColor(GREEN); + dots2[0].setBackgroundColor(GRAY); + dots2[2].setBackgroundColor(GRAY); + dots2[3].setBackgroundColor(GRAY); + } + if (j % 4 == 2) { + dots2[2].setBackgroundColor(GREEN); + dots2[1].setBackgroundColor(GRAY); + dots2[0].setBackgroundColor(GRAY); + dots2[3].setBackgroundColor(GRAY); + } + if (j % 4 == 3) { + dots2[3].setBackgroundColor(GREEN); + dots2[1].setBackgroundColor(GRAY); + dots2[2].setBackgroundColor(GRAY); + dots2[0].setBackgroundColor(GRAY); + } + } + + public void onImageTapped(View image) { + } + { + StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); + StrictMode.setThreadPolicy(policy); } } diff --git a/MyFirstSlideshow/app/src/main/res/layout/activity_main.xml b/MyFirstSlideshow/app/src/main/res/layout/activity_main.xml index 0b886d0..d6d77e4 100644 --- a/MyFirstSlideshow/app/src/main/res/layout/activity_main.xml +++ b/MyFirstSlideshow/app/src/main/res/layout/activity_main.xml @@ -4,11 +4,87 @@ android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.charles.myfirstslideshow.MainActivity"> + - + + + + + + + +