Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
devliber committed Sep 11, 2016
0 parents commit f7acbb8
Show file tree
Hide file tree
Showing 34 changed files with 951 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Built application files
*.apk
*.ap_

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/

# Gradle files
.gradle/
build/

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

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# Intellij
*.iml
.idea/workspace.xml
.idea/libraries

# Keystore files
*.jks
1 change: 1 addition & 0 deletions .idea/.name

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

22 changes: 22 additions & 0 deletions .idea/compiler.xml

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

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

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

8 changes: 8 additions & 0 deletions .idea/dictionaries/Aurelian.xml

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

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

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

24 changes: 24 additions & 0 deletions .idea/gradle.xml

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

46 changes: 46 additions & 0 deletions .idea/misc.xml

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

9 changes: 9 additions & 0 deletions .idea/modules.xml

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

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

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

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

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

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
25 changes: 25 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion '24.0.2'
defaultConfig {
applicationId "com.appgramming.lonecolor"
minSdkVersion 11
targetSdkVersion 24
versionCode 4
versionName '1.2'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\Dev\AppData\Local\Android\android-studio\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.appgramming.lonecolor;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
29 changes: 29 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.appgramming.lonecolor">

<uses-permission android:name="android.permission.SET_WALLPAPER"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:installLocation="auto"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".StartActivity"
android:excludeFromRecents="true"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

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

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright (C) 2014-2016 Appgramming. All rights reserved.
* http://www.appgramming.com
*/
package com.appgramming.lonecolor;

import android.content.ClipData;
import android.content.ClipDescription;
import android.content.ClipboardManager;
import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;

/**
* A static method to get a valid color value from the clipboard.
*/
final class ColorClipParameter {

/**
* Gets the current clip parameter from the clipboard.
*
* @return The text value of the clip parameter, or null if there is no text on the clipboard.
*/
private static String getClipParameter(Context context) {
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
if ((clipboard != null) && clipboard.hasPrimaryClip()) {

// Get the current primary clip on the clipboard
final ClipData clip = clipboard.getPrimaryClip();
if ((clip != null) && (clip.getItemCount() > 0)) {

final ClipDescription description = clip.getDescription();

// Return null if the clipboard does not contain plain text or html text
if (!description.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN) &&
!description.hasMimeType(ClipDescription.MIMETYPE_TEXT_HTML)) {
return null;
}

// Ignore and return null if it's a clip previously copied by LoneColor
final CharSequence label = description.getLabel();
if ((label != null) && (label.equals(context.getString(R.string.app_name)))) {
return null;
}

// Get the text from the clipboard
final CharSequence sequence = clip.getItemAt(0).getText();
if (sequence != null) {
return sequence.toString();
}
}
}

return null;
}

/**
* Returns the value of the color clip parameter.
*
* @return An Integer color value, or null.
*/
public static Integer getColor(Context context) {

// Get the clip parameter from the clipboard
final String clipText = ColorClipParameter.getClipParameter(context);

// Return null if the clip is null or empty
if (TextUtils.isEmpty(clipText)) {
return null;
}

// Try to parse the clip parameter to a color value, "as it is"
try {
return Color.parseColor(clipText);
} catch (IllegalArgumentException ignored) {
// Ignore error, try next color format
}

// Try to parse the clip parameter with a "#" in front
try {
return Color.parseColor('#' + clipText);
} catch (IllegalArgumentException ignored) {
// Ignore error, we will return false
}

// No valid color, return null
return null;
}
}
Loading

0 comments on commit f7acbb8

Please sign in to comment.