Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
adneal committed Feb 23, 2014
0 parents commit 8b606ef
Show file tree
Hide file tree
Showing 24 changed files with 552 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# built application files
*.apk
*.ap_

# files for the dex VM
*.dex

# Java class files
*.class

# generated files
bin/
gen/

# Local configuration file (sdk path, etc)
local.properties
project.properties

# Eclipse project files
.classpath
.project
.settings

# Proguard folder generated by Eclipse
proguard/
proguard-project.txt

# Intellij project files
*.iml
*.ipr
*.iws
.idea/
51 changes: 51 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 Andrew Neal -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="org.seeingpixels.muzei.patterns"
android:versionCode="1"
android:versionName="1.0" >

<!-- Jelly Bean - KitKat -->
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="19" />

<!-- Used to check for a network connection -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Used to access the Internet (image fetching, meta data) -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Used to keep the processor from sleeping or screen from dimming -->
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Light" >

<!-- Muzei settings -->
<activity
android:name="org.seeingpixels.muzei.patterns.app.activity.PreferenceActivity"
android:exported="true"
android:label="@string/muzei_settings"
android:theme="@android:style/Theme.Holo.Light.DarkActionBar" />

<!-- Muzei Service -->
<service
android:name="org.seeingpixels.muzei.patterns.app.PatternsRemoteArtSource"
android:description="@string/muzei_desc"
android:icon="@drawable/ic_muzei_launcher"
android:label="@string/muzei_label"
tools:ignore="ExportedService" >
<intent-filter>
<action android:name="com.google.android.apps.muzei.api.MuzeiArtSource" />
</intent-filter>

<meta-data
android:name="settingsActivity"
android:value="org.seeingpixels.muzei.patterns.app.activity.PreferenceActivity" />
</service>
</application>

</manifest>
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#Patters for Muzei

## About

**[Patterns](http://www.colourlovers.com/patterns) wallpapers for [Muzei](http://get.muzei.co/).**

## Screenshots

![Screenshots](http://i.imgur.com/LAUxx6K.png)

## Dependencies

* [Muzei-API](http://api.muzei.co/) (Apache License 2.0)

## License

**Copyright 2014 Andrew Neal**
Binary file added ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ic_muzei_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added libs/muzei-api-v1.0.jar
Binary file not shown.
Binary file added res/drawable-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/ic_muzei_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/ic_muzei_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/ic_muzei_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xxhdpi/ic_muzei_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 Andrew Neal -->
<resources>

<!-- Wallpaper rotation entries -->
<string-array name="pref_wallpaper_rotation_entries">
<item>Don\'t change wallpaper</item>
<item>Every hour</item>
<item>Every 3 hours</item>
<item>Every 6 hours</item>
<item>Every 24 hours</item>
<item>Every 3 days</item>
</string-array>
<!-- Wallpaper rotation values -->
<string-array name="pref_wallpaper_rotation_values">
<item>0</item>
<item>1</item>
<item>3</item>
<item>6</item>
<item>24</item>
<item>72</item>
</string-array>

</resources>
31 changes: 31 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 Andrew Neal -->
<resources>

<!-- App -->
<string name="app_name">Patterns for Muzei</string>

<!-- Muzei app -->
<string name="muzei_label">Patterns</string>
<string name="muzei_desc">Random wallpaper patterns from Colour Lovers</string>
<string name="muzei_settings">Settings</string>

<!--
// //////////////////////////////////////////////////////////////////////////
// Preferences
// //////////////////////////////////////////////////////////////////////////
-->
<!-- Preference categories -->
<string name="pref_category_setup">Setup</string>
<string name="pref_category_about">About</string>

<!-- Update interval -->
<string name="pref_update_interval_key">pref_update_interval_key</string>
<string name="pref_update_interval">Update interval</string>
<string name="pref_update_interval_default">1</string>

<!-- About -->
<string name="pref_about_author_title">Author</string>
<string name="pref_about_author_summary">Andrew Neal</string>

</resources>
27 changes: 27 additions & 0 deletions res/xml/preferences.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2014 Andrew Neal -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

<!-- Setup -->
<PreferenceCategory android:title="@string/pref_category_setup" >

<!-- Wallpaper rotation interval -->
<ListPreference
android:defaultValue="@string/pref_update_interval_default"
android:entries="@array/pref_wallpaper_rotation_entries"
android:entryValues="@array/pref_wallpaper_rotation_values"
android:key="@string/pref_update_interval_key"
android:persistent="true"
android:summary="%s"
android:title="@string/pref_update_interval" />
</PreferenceCategory>

<!-- About -->
<PreferenceCategory android:title="@string/pref_category_about" >
<Preference
android:selectable="false"
android:summary="@string/pref_about_author_summary"
android:title="@string/pref_about_author_title" />
</PreferenceCategory>

</PreferenceScreen>
21 changes: 21 additions & 0 deletions src/org/seeingpixels/muzei/patterns/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (C) 2014 Andrew Neal
*/

package org.seeingpixels.muzei.patterns;

/**
* App-wide constants
*
* @author Andrew Neal ([email protected])
*/
public final class Config {

/** The Color Lovers random wallpaper API */
public static final String API = "http://www.colourlovers.com/api/patterns/random&format=json";

/* This class is never initialized */
private Config() {
}

}
117 changes: 117 additions & 0 deletions src/org/seeingpixels/muzei/patterns/app/PatternsRemoteArtSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright (C) 2014 Andrew Neal
*/

package org.seeingpixels.muzei.patterns.app;

import android.content.Intent;
import android.net.Uri;
import android.preference.PreferenceManager;

import com.google.android.apps.muzei.api.Artwork;
import com.google.android.apps.muzei.api.RemoteMuzeiArtSource;

import org.json.JSONException;
import org.seeingpixels.muzei.patterns.Config;
import org.seeingpixels.muzei.patterns.R;
import org.seeingpixels.muzei.patterns.model.Pattern;
import org.seeingpixels.muzei.patterns.util.CloseableUtils;
import org.seeingpixels.muzei.patterns.util.IOUtils;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
* @author Andrew Neal ([email protected])
*/
public class PatternsRemoteArtSource extends RemoteMuzeiArtSource {

/** The name of the worker {@link Thread} */
private static final String SIMPLE_DESKTOPS = "PatternsRemoteArtSource";

/** Indicates to schedule an immediate update */
public static final String ACTION_UPDATE = "patterns.muzei.intent.action.UPDATE";

/**
* Constructor for <code>PatternsRemoteArtSource</code>
*/
public PatternsRemoteArtSource() {
super(SIMPLE_DESKTOPS);
}

/**
* {@inheritDoc}
*/
@Override
public void onCreate() {
super.onCreate();
setUserCommands(BUILTIN_COMMAND_ID_NEXT_ARTWORK);
}

/**
* {@inheritDoc}
*/
@Override
protected void onHandleIntent(Intent intent) {
super.onHandleIntent(intent);
if (intent != null && intent.getAction().equals(ACTION_UPDATE)) {
scheduleNext();
}
}

/**
* {@inheritDoc}
*/
@Override
protected void onTryUpdate(int reason) throws RetryException {
// The Pattern to download
Pattern pattern = null;

// Parse the SimpleDesktops API
InputStream in = null;
try {
final URL url = new URL(Config.API);
in = new BufferedInputStream(url.openStream());
pattern = new Pattern(IOUtils.toString(in));
} catch (final IOException ignored) {
// Nothing to do
} catch (final JSONException ignored) {
// Nothing to do
} finally {
CloseableUtils.closeQuietly(in);
}

if (pattern == null) {
throw new RetryException();
}

// Check for a current token
final Artwork artwork = getCurrentArtwork();
final String token = artwork != null ? artwork.getToken() : pattern.token;

// Display the wallpaper in Muzei
publishArtwork(new Artwork.Builder()
.imageUri(Uri.parse(pattern.img))
.title(pattern.title)
.byline(pattern.user)
.token(token)
.viewIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(pattern.permalink)))
.build());

// Schedule another update
scheduleNext();
}

/** Schedules a new update based on user preference */
private void scheduleNext() {
final int updateInterval = Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(
this).getString(getString(R.string.pref_update_interval_key),
getString(R.string.pref_update_interval_default)));
if (updateInterval > 0) {
scheduleUpdate(System.currentTimeMillis() + 60 * updateInterval * 60 * 1000);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2014 Andrew Neal
*/

package org.seeingpixels.muzei.patterns.app.activity;

import android.app.Activity;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;

import org.seeingpixels.muzei.patterns.app.PatternsRemoteArtSource;
import org.seeingpixels.muzei.patterns.app.fragment.PrefsFragment;

/**
* An {@link Activity} used to manage the {@link PrefsFragment} for the app
*
* @author Andrew Neal ([email protected])
*/
public class PreferenceActivity extends Activity {

/**
* {@inheritDoc}
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set up the ActionBar
getActionBar().setDisplayHomeAsUpEnabled(true);

// Load the preferences
if (savedInstanceState == null) {
final FragmentTransaction fOps = getFragmentManager().beginTransaction();
fOps.replace(android.R.id.content, new PrefsFragment()).commit();
}
}

/**
* {@inheritDoc}
*/
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
finish();
}
return super.onOptionsItemSelected(item);
}

/**
* {@inheritDoc}
*/
@Override
protected void onDestroy() {
// Schedule a new update
final Intent muzei = new Intent(this, PatternsRemoteArtSource.class);
muzei.setAction(PatternsRemoteArtSource.ACTION_UPDATE);
startService(muzei);
super.onDestroy();
}

}
Loading

0 comments on commit 8b606ef

Please sign in to comment.