Skip to content

Commit

Permalink
Simplify changing the wallpaper - stop using an IntentService
Browse files Browse the repository at this point in the history
  • Loading branch information
devliber committed Dec 30, 2016
1 parent 603d4b8 commit 1695fd3
Show file tree
Hide file tree
Showing 19 changed files with 395 additions and 264 deletions.
98 changes: 97 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

# Created by https://www.gitignore.io/api/android,intellij+iml,java,gradle

### Android ###
# Built application files
*.apk
*.ap_
Expand Down Expand Up @@ -35,7 +39,99 @@ captures/
# Intellij
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/libraries

# Keystore files
*.jks
*.jks

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

### Android Patch ###
gen-external-apklibs


### Intellij+iml ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff:

# Sensitive or high-churn files:
.idea/dataSources/
.idea/dataSources.ids
.idea/dataSources.xml
.idea/dataSources.local.xml
.idea/sqlDataSources.xml
.idea/dynamic.xml
.idea/uiDesigner.xml

# Gradle:
.idea/gradle.xml

# Mongo Explorer plugin:
.idea/mongoSettings.xml

## File-based project format:
*.iws

## Plugin-specific files:

# IntelliJ
/out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

### Intellij+iml Patch ###
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

modules.xml
.idea/misc.xml
*.ipr


### Java ###

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*


### Gradle ###
.gradle
/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

# End of https://www.gitignore.io/api/android,intellij+iml,java,gradle
1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

13 changes: 3 additions & 10 deletions .idea/dictionaries/LoneColor.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions .idea/encodings.xml

This file was deleted.

7 changes: 1 addition & 6 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
apply plugin: 'com.android.application'

//noinspection GroovyMissingReturnStatement
android {
compileSdkVersion 24
buildToolsVersion '24.0.2'
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
applicationId "com.appgramming.lonecolor"
minSdkVersion 11
targetSdkVersion 24
targetSdkVersion 25
versionCode 5
versionName '2.0-beta'
versionName '2.0'
}
buildTypes {
release {
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".StartActivity"
android:name=".LoneColorActivity"
android:excludeFromRecents="true"
android:label="@string/app_name">
<intent-filter>
Expand All @@ -24,9 +24,6 @@
</intent-filter>
</activity>

<service
android:name=".LoneColorWallpaperService"
android:exported="false"/>
</application>

</manifest>
81 changes: 81 additions & 0 deletions app/src/main/java/com/appgramming/lonecolor/LoneColorActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright (C) 2014-2016 Appgramming
* http://www.appgramming.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.appgramming.lonecolor;

import android.app.Activity;
import android.os.Bundle;

import com.appgramming.lonecolor.utils.ColorClipboardParameter;
import com.appgramming.lonecolor.utils.ColorWallpaper;
import com.appgramming.lonecolor.utils.GoodRandomColor;
import com.appgramming.lonecolor.utils.Utils;

import java.io.IOException;

/**
* LoneColor zero interface activity: just sets the color wallpaper and finishes.
*/
public class LoneColorActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Set the color wallpaper
setColorWallpaper();

// Finish the activity
finish();
}

/**
* Sets the color wallpaper to the color value in the Clipboard, or to a random color.
*/
private void setColorWallpaper() {

// Try to get the color parameter from the clipboard
Integer colorParam = null;
try {
colorParam = ColorClipboardParameter.getColor(getApplication());
} catch (Exception ignored) {
// An unexpected exception while trying to get the color code from the clipboard
// can crash the app at startup. Ignore any exceptions, we will generate a random
// color anyway.
}

// If there is no valid color value in the clipboard, generate a random color
final int color = (colorParam != null) ? colorParam : GoodRandomColor.nextColor();

try {
// Set the color wallpaper
ColorWallpaper.setColorWallpaper(this, color);

// Success: copy the color code to the clipboard
Utils.copyText(this, Utils.colorToHex(color));

// Go to the home screen
Utils.goHome(this);

} catch (IOException e) {

// Write the stack trace to System.err and copy the reason of the failure to clipboard
e.printStackTrace();
Utils.copyText(this, e.toString());
}
}
}
Loading

0 comments on commit 1695fd3

Please sign in to comment.