├── settings.gradle
├── foregroundviews
├── src
│ └── main
│ │ ├── AndroidManifest.xml
│ │ ├── res
│ │ └── values
│ │ │ └── attrs.xml
│ │ └── java
│ │ └── com
│ │ └── cesards
│ │ └── android
│ │ └── foregroundviews
│ │ ├── ForegroundTextView.java
│ │ ├── ForegroundLinearLayout.java
│ │ ├── ForegroundRelativeLayout.java
│ │ └── ForegroundImageView.java
└── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── foregroundviews-samples
├── src
│ └── main
│ │ ├── res
│ │ ├── drawable-hdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ │ ├── bg_card.9.png
│ │ │ └── ic_launcher.png
│ │ ├── drawable-xxhdpi
│ │ │ └── ic_launcher.png
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── styles.xml
│ │ │ ├── dimens.xml
│ │ │ └── strings.xml
│ │ ├── drawable
│ │ │ ├── fg_card_pressed.xml
│ │ │ └── fg_card.xml
│ │ └── layout
│ │ │ ├── list_card.xml
│ │ │ ├── row_linear_item.xml
│ │ │ ├── row_relative_item.xml
│ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── cesards
│ │ └── android
│ │ └── samples
│ │ └── foregroundviews
│ │ ├── LinearsActivity.java
│ │ ├── RelativesActivity.java
│ │ ├── ListActivity.java
│ │ └── MainActivity.java
└── build.gradle
├── gradle.properties
├── .gitignore
├── README.md
├── codestyles_DogmaLabs.xml
└── LICENSE
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':foregroundviews', ':foregroundviews-samples'
2 |
--------------------------------------------------------------------------------
/foregroundviews/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cesards/ForegroundViews/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cesards/ForegroundViews/HEAD/foregroundviews-samples/src/main/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cesards/ForegroundViews/HEAD/foregroundviews-samples/src/main/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/res/drawable-xhdpi/bg_card.9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cesards/ForegroundViews/HEAD/foregroundviews-samples/src/main/res/drawable-xhdpi/bg_card.9.png
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cesards/ForegroundViews/HEAD/foregroundviews-samples/src/main/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cesards/ForegroundViews/HEAD/foregroundviews-samples/src/main/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #33FF4444
5 |
6 |
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/res/drawable/fg_card_pressed.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Apr 10 15:27:10 PDT 2013
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
7 |
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | ForegroundViews
5 | Hello world!
6 | Settings
7 |
8 |
9 |
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/res/drawable/fg_card.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/res/layout/list_card.xml:
--------------------------------------------------------------------------------
1 |
15 |
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/res/layout/row_linear_item.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/res/layout/row_relative_item.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
19 |
20 |
--------------------------------------------------------------------------------
/foregroundviews/src/main/res/values/attrs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
6 |
7 |
9 |
10 |
11 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/foregroundviews-samples/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'hugo'
3 |
4 | buildscript {
5 | repositories {
6 | jcenter()
7 | }
8 |
9 | dependencies {
10 | classpath 'com.jakewharton.hugo:hugo-plugin:1.2.0'
11 | }
12 | }
13 |
14 | android {
15 | compileSdkVersion 21
16 | buildToolsVersion "21.1.2"
17 | defaultConfig {
18 | applicationId 'com.cesards.android.samples.foregroundviews'
19 | minSdkVersion 14
20 | targetSdkVersion 21
21 | versionCode 1
22 | versionName "1.0.0"
23 | }
24 | compileOptions {
25 | sourceCompatibility JavaVersion.VERSION_1_7
26 | targetCompatibility JavaVersion.VERSION_1_7
27 | }
28 | buildTypes {
29 | release {
30 | minifyEnabled false
31 | }
32 | }
33 | productFlavors {}
34 | }
35 |
36 | dependencies {
37 | compile 'com.android.support:support-v4:21.0.3'
38 | compile 'me.relex:circleindicator:1.1.1@aar'
39 | compile 'com.jakewharton:butterknife:6.1.0'
40 | compile project(':foregroundviews')
41 | }
42 |
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/java/com/cesards/android/samples/foregroundviews/LinearsActivity.java:
--------------------------------------------------------------------------------
1 | package com.cesards.android.samples.foregroundviews;
2 |
3 | /*
4 | * Copyright 2014 DogmaLabs
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import android.widget.ArrayAdapter;
20 |
21 | public class LinearsActivity extends ListActivity {
22 |
23 | @Override
24 | protected void setInitialData() {
25 | listView.setAdapter(new ArrayAdapter<>(this, R.layout.row_linear_item, android.R.id.text1, titles));
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/java/com/cesards/android/samples/foregroundviews/RelativesActivity.java:
--------------------------------------------------------------------------------
1 | package com.cesards.android.samples.foregroundviews;
2 |
3 | /*
4 | * Copyright 2014 DogmaLabs
5 | *
6 | * Licensed under the Apache License, Version 2.0 (the "License");
7 | * you may not use this file except in compliance with the License.
8 | * You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing, software
13 | * distributed under the License is distributed on an "AS IS" BASIS,
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | * See the License for the specific language governing permissions and
16 | * limitations under the License.
17 | */
18 |
19 | import android.widget.ArrayAdapter;
20 |
21 | public class RelativesActivity extends ListActivity {
22 |
23 | @Override
24 | protected void setInitialData() {
25 | listView.setAdapter(new ArrayAdapter(this, R.layout.row_relative_item, android.R.id.text1, titles));
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/java/com/cesards/android/samples/foregroundviews/ListActivity.java:
--------------------------------------------------------------------------------
1 | package com.cesards.android.samples.foregroundviews;/*
2 | * Copyright 2014 DogmaLabs
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import android.app.Activity;
18 | import android.os.Bundle;
19 | import android.widget.ListView;
20 |
21 | public abstract class ListActivity extends Activity {
22 |
23 | // Constants
24 | protected static final String[] titles = new String[] {
25 | "Card 1", "Card 2", "Card 3", "Card 4", "Card 5", "Card 6", "Card 7", "Card 8", "Card 9", "Card 10"
26 | };
27 | // Views
28 | ListView listView;
29 |
30 | // Headers
31 | protected abstract void setInitialData();
32 |
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 | setContentView(R.layout.list_card);
37 | listView = (ListView) findViewById(android.R.id.list);
38 | setInitialData();
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | #
2 | # Copyright 2014 DogmaLabs
3 | #
4 | # Licensed under the Apache License, Version 2.0 (the "License");
5 | # you may not use this file except in compliance with the License.
6 | # You may obtain a copy of the License at
7 | #
8 | # http://www.apache.org/licenses/LICENSE-2.0
9 | #
10 | # Unless required by applicable law or agreed to in writing, software
11 | # distributed under the License is distributed on an "AS IS" BASIS,
12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | # See the License for the specific language governing permissions and
14 | # limitations under the License.
15 | #
16 |
17 | # Project-wide Gradle settings.
18 |
19 | # IDE (e.g. Android Studio) users:
20 | # Settings specified in this file will override any Gradle settings
21 | # configured through the IDE.
22 |
23 | # For more details on how to configure your build environment visit
24 | # http://www.gradle.org/docs/current/userguide/build_environment.html
25 |
26 | # Specifies the JVM arguments used for the daemon process.
27 | # The setting is particularly useful for tweaking memory settings.
28 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
29 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
30 |
31 | # When configured, Gradle will run in incubating parallel mode.
32 | # This option should only be used with decoupled projects. More details, visit
33 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
34 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/java/com/cesards/android/samples/foregroundviews/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.cesards.android.samples.foregroundviews;/*
2 | * Copyright 2014 DogmaLabs
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import android.app.Activity;
18 | import android.content.Intent;
19 | import android.os.Bundle;
20 | import android.view.View;
21 | import butterknife.ButterKnife;
22 | import butterknife.OnClick;
23 |
24 | public class MainActivity extends Activity {
25 |
26 | @Override protected void onCreate(Bundle savedInstanceState) {
27 | super.onCreate(savedInstanceState);
28 | setContentView(R.layout.activity_main);
29 | ButterKnife.inject(this);
30 | }
31 |
32 | @OnClick({R.id.linears, R.id.relatives, R.id.texts, R.id.images}) public void onItemClick(View v) {
33 | switch (v.getId()) {
34 | case R.id.linears:
35 | startActivity(new Intent(this, LinearsActivity.class));
36 | break;
37 | case R.id.relatives:
38 | startActivity(new Intent(this, RelativesActivity.class));
39 | break;
40 | case R.id.texts:
41 | break;
42 | case R.id.images:
43 | break;
44 | }
45 | }
46 |
47 |
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Copyright: César Díez (m3n0R) https://github.com/m3n0R
2 | # Under CC-BY-SA V3.0 (https://creativecommons.org/licenses/by-sa/3.0/legalcode)
3 |
4 | ### Android ###
5 | # Built application files
6 | *.apk
7 | *.ap_
8 |
9 | ### Files for the Dalvik VM ###
10 | *.dex
11 |
12 | ### Generated files ###
13 | bin/
14 | gen/
15 | classes/
16 | gen-external-apklibs/
17 |
18 | ### Gradle files ###
19 | .gradle/
20 | build/
21 |
22 | ### Local configuration file (sdk path, etc) ###
23 | local.properties
24 |
25 | ### Proguard folder generated by Eclipse ###
26 | proguard/
27 |
28 | ### Proguard files ###
29 | out.map
30 | unused.txt
31 |
32 | ### Log Files ###
33 | *.log
34 |
35 | ### Intellij ###
36 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
37 |
38 | ### Directory-based project format ###
39 | .idea/
40 | # if you remove the above rule, at least ignore user-specific stuff:
41 | # .idea/workspace.xml
42 | # .idea/tasks.xml
43 | # and these sensitive or high-churn files:
44 | # .idea/dataSources.ids
45 | # .idea/dataSources.xml
46 | # .idea/sqlDataSources.xml
47 | # .idea/dynamic.xml
48 |
49 | ### File-based project format ###
50 | *.ipr
51 | *.iml
52 | *.iws
53 |
54 | ### Additional for IntelliJ ###
55 | out/
56 |
57 | ### generated by mpeltonen/sbt-idea plugin ###
58 | .idea_modules/
59 |
60 | ### generated by JIRA plugin ###
61 | atlassian-ide-plugin.xml
62 |
63 | ### generated by Crashlytics plugin (for Android Studio and Intellij) ###
64 | com_crashlytics_export_strings.xml
65 |
66 | ### Java ###
67 | *.class
68 |
69 | ### OS stuff ###
70 | .DS_Store
71 |
72 | ### Windows files ###
73 | Thumbs.db
74 |
75 | ### plugin mirror ###
76 | /app/mirror
77 |
78 | ### fabric ###
79 | /app/src/main/assets/crashlytics-build.properties
80 |
81 | ### svn files ###
82 | .svn
83 |
84 | ### lint folder ###
85 | lint
86 |
87 | ### maven output folder ###
88 | target
89 |
90 | ### vi swap files ###
91 | *.swp
92 |
93 | ### backup files ###
94 | *.bak
--------------------------------------------------------------------------------
/foregroundviews/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'com.jfrog.bintray'
4 |
5 | android {
6 | compileSdkVersion 21
7 | buildToolsVersion "21.1.2"
8 |
9 | defaultConfig {
10 | minSdkVersion 14
11 | targetSdkVersion 21
12 | versionCode 1
13 | versionName "1.0.0"
14 | }
15 |
16 | compileOptions {
17 | sourceCompatibility JavaVersion.VERSION_1_7
18 | targetCompatibility JavaVersion.VERSION_1_7
19 | }
20 | }
21 |
22 | def siteUrl = 'https://github.com/cesards/ForegroundViews'
23 | // Homepage URL of the library
24 | def gitUrl = 'https://github.com/cesards/ForegroundViews.git'
25 | // Git repository URL
26 | // This is the library version used when deploying the artifact
27 | version = "1.0.0"
28 | group = "com.cesards.android"
29 |
30 | Properties properties = new Properties()
31 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
32 |
33 | bintray {
34 | user = properties.getProperty("bintray.user")
35 | key = properties.getProperty("bintray.apikey")
36 |
37 | configurations = ['archives']
38 | pkg {
39 | repo = "maven"
40 | name = "ForegroundViews"
41 | websiteUrl = siteUrl
42 | vcsUrl = gitUrl
43 | licenses = ["Apache-2.0"]
44 | publish = true
45 | }
46 | }
47 |
48 | install {
49 | repositories.mavenInstaller {
50 | // This generates POM.xml with proper parameters
51 | pom {
52 | project {
53 | packaging 'aar'
54 |
55 | // Add your description here
56 | name 'Foreground Views'
57 | url siteUrl
58 |
59 | // Set your license
60 | licenses {
61 | license {
62 | name 'The Apache Software License, Version 2.0'
63 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
64 | }
65 | }
66 | developers {
67 | developer {
68 | id 'cesards'
69 | name 'Cesar Diez'
70 | email 'cesaryomismo@gmail.com'
71 | }
72 | }
73 | scm {
74 | connection gitUrl
75 | developerConnection gitUrl
76 | url siteUrl
77 | }
78 | }
79 | }
80 | }
81 | }
82 |
83 | task sourcesJar(type: Jar) {
84 | from android.sourceSets.main.java.srcDirs
85 | classifier = 'sources'
86 | }
87 |
88 | task javadoc(type: Javadoc) {
89 | source = android.sourceSets.main.java.srcDirs
90 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
91 | }
92 |
93 | task javadocJar(type: Jar, dependsOn: javadoc) {
94 | classifier = 'javadoc'
95 | from javadoc.destinationDir
96 | }
97 | artifacts {
98 | archives javadocJar
99 | archives sourcesJar
100 | }
--------------------------------------------------------------------------------
/foregroundviews-samples/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
21 |
22 |
30 |
31 |
32 | >
33 |
34 |
42 |
43 |
51 |
52 |
53 |
54 |
65 |
66 |
77 |
78 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ForegroundViews
2 | =======
3 | Small library that provides Foreground View functionality to most used Android Views with foreground.
4 | If you want support to new View, add an issue :-)
5 |
6 | This library is developed based on some other good but not completed approaches of Foreground Views:
7 |
8 |
9 | ### Sources
10 | * [FRelativeLayout][1] made by [Shaka Huang][2]
11 | * [Antonie Merle][3] [post][4] about how custom Foreground Views should work
12 | * [Chris Banes][5] [post][6] that explains which possibilities we have to get the Foreground
13 | Approach on Android
14 | * [FrameLayout source code][7]
15 |
16 | Screenshots
17 | -----------
18 |
19 | Usage
20 | -----
21 | You just have to use whatever FView like FrameLayout; just set the android:foreground attribute
22 | as shown below:
23 | ```
24 |
30 |
31 | ... other views ...
32 |
33 |
34 | ```
35 | where custom attributes can be:
36 |
37 | * __foreground__
38 | Defines the drawable to draw over the content. This can be used as an overlay.
39 |
40 | Just add: ```custom:foreground="@drawable/your_foreground"```
41 |
42 | * __foregroundInsidePadding__
43 | Defines whether the foreground drawable should be drawn inside the padding.
44 | This property is false by default except if your background is a NinePatch Drawable.
45 |
46 | Just add: ```custom:foregroundInsidePadding="true"```
47 |
48 | * __backgroundAsForeground__
49 | Retrieve the default background and set it as the foreground. Thanks to this, you can get the
50 | default background selector of your theme and set it as your foreground selector if you want.
51 | This property is false by default.
52 |
53 | Just add: ```custom:foregroundInsidePadding="true"```
54 |
55 |
56 | Download
57 | --------
58 | Not yet.
59 |
60 | Download [the latest JAR][4] or grab via Maven:
61 | ```xml
62 |
63 | ```
64 | or Gradle:
65 | ```groovy
66 | # Coming soon
67 | ```
68 |
69 | Developed By
70 | ------------
71 | * César Díez Sánchez -
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 | License
93 | -------
94 |
95 | Copyright 2014 DogmaLabs
96 |
97 | Licensed under the Apache License, Version 2.0 (the "License");
98 | you may not use this file except in compliance with the License.
99 | You may obtain a copy of the License at
100 |
101 | http://www.apache.org/licenses/LICENSE-2.0
102 |
103 | Unless required by applicable law or agreed to in writing, software
104 | distributed under the License is distributed on an "AS IS" BASIS,
105 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
106 | See the License for the specific language governing permissions and
107 | limitations under the License.
108 |
109 |
110 | [1]: https://gist.github.com/shakalaca/6199283
111 | [2]: https://github.com/shakalaca
112 | [3]: https://github.com/castorflex
113 | [4]: http://antoine-merle.com/blog/2013/07/17/adding-a-foreground-selector-to-a-view/
114 | [5]: https://github.com/chrisbanes
115 | [6]: https://plus.google.com/+AndroidDevelopers/posts/aHPVDtr6mcp
116 | [7]: https://github.com/android/platform_frameworks_base/blob/master/core/java/android/widget/FrameLayout.java
117 |
--------------------------------------------------------------------------------
/foregroundviews/src/main/java/com/cesards/android/foregroundviews/ForegroundTextView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 DogmaLabs
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.cesards.android.foregroundviews;
18 |
19 | import android.annotation.TargetApi;
20 | import android.content.Context;
21 | import android.content.res.TypedArray;
22 | import android.graphics.Canvas;
23 | import android.graphics.Rect;
24 | import android.graphics.drawable.Drawable;
25 | import android.graphics.drawable.NinePatchDrawable;
26 | import android.os.Build;
27 | import android.util.AttributeSet;
28 | import android.view.MotionEvent;
29 | import android.widget.TextView;
30 |
31 | public class ForegroundTextView extends TextView {
32 |
33 | // UI
34 | private Drawable foreground;
35 |
36 | // Controller/logic fields
37 | private final Rect rectPadding = new Rect();
38 | private boolean foregroundPadding = false;
39 | private boolean foregroundBoundsChanged = false;
40 | private boolean backgroundAsForeground = false;
41 |
42 | // Constructors
43 | public ForegroundTextView(Context context) {
44 | super(context);
45 | }
46 |
47 | public ForegroundTextView(Context context, AttributeSet attrs) {
48 | this(context, attrs, 0);
49 | }
50 |
51 | public ForegroundTextView(Context context, AttributeSet attrs, int defStyle) {
52 | super(context, attrs, defStyle);
53 |
54 | final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundLayout, defStyle, 0);
55 |
56 | final Drawable d = a.getDrawable(R.styleable.ForegroundLayout_foreground);
57 | foregroundPadding = a.getBoolean(R.styleable.ForegroundLayout_foregroundInsidePadding, false);
58 |
59 | backgroundAsForeground = a.getBoolean(R.styleable.ForegroundLayout_backgroundAsForeground, false);
60 |
61 | // Apply foreground padding for ninepatches automatically
62 | if (!foregroundPadding && getBackground() instanceof NinePatchDrawable) {
63 | final NinePatchDrawable npd = (NinePatchDrawable) getBackground();
64 | if (npd != null && npd.getPadding(rectPadding)) {
65 | foregroundPadding = true;
66 | }
67 | }
68 |
69 | final Drawable b = getBackground();
70 | if (backgroundAsForeground && b != null) {
71 | setForeground(b);
72 | } else if (d != null) {
73 | setForeground(d);
74 | }
75 |
76 | a.recycle();
77 | }
78 |
79 | /**
80 | * Supply a Drawable that is to be rendered on top of all of the child views in the layout.
81 | *
82 | * @param drawable The Drawable to be drawn on top of the children.
83 | */
84 | public void setForeground(Drawable drawable) {
85 | if (foreground != drawable) {
86 | if (foreground != null) {
87 | foreground.setCallback(null);
88 | unscheduleDrawable(foreground);
89 | }
90 |
91 | foreground = drawable;
92 |
93 | if (drawable != null) {
94 | setWillNotDraw(false);
95 | drawable.setCallback(this);
96 | if (drawable.isStateful()) {
97 | drawable.setState(getDrawableState());
98 | }
99 | } else {
100 | setWillNotDraw(true);
101 | }
102 | requestLayout();
103 | invalidate();
104 | }
105 | }
106 |
107 | /**
108 | * Returns the drawable used as the foreground of this layout. The foreground drawable,
109 | * if non-null, is always drawn on top of the children.
110 | *
111 | * @return A Drawable or null if no foreground was set.
112 | */
113 | public Drawable getForeground() {
114 | return foreground;
115 | }
116 |
117 | @Override
118 | protected void drawableStateChanged() {
119 | super.drawableStateChanged();
120 |
121 | if (foreground != null && foreground.isStateful()) {
122 | foreground.setState(getDrawableState());
123 | }
124 | }
125 |
126 | @Override
127 | protected boolean verifyDrawable(Drawable who) {
128 | return super.verifyDrawable(who) || (who == foreground);
129 | }
130 |
131 | @Override
132 | public void jumpDrawablesToCurrentState() {
133 | super.jumpDrawablesToCurrentState();
134 |
135 | if (foreground != null) {
136 | foreground.jumpToCurrentState();
137 | }
138 | }
139 |
140 | @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) {
141 | super.onSizeChanged(w, h, oldw, oldh);
142 | foregroundBoundsChanged = true;
143 | }
144 |
145 | @Override
146 | public void draw(Canvas canvas) {
147 | super.draw(canvas);
148 |
149 | if (foreground != null) {
150 | final Drawable foreground = this.foreground;
151 |
152 | if (foregroundBoundsChanged) {
153 | foregroundBoundsChanged = false;
154 |
155 | final int w = getRight() - getLeft();
156 | final int h = getBottom() - getTop();
157 |
158 | if (foregroundPadding) {
159 | foreground.setBounds(rectPadding.left, rectPadding.top, w - rectPadding.right, h - rectPadding.bottom);
160 | } else {
161 | foreground.setBounds(0, 0, w, h);
162 | }
163 | }
164 | foreground.draw(canvas);
165 | }
166 | }
167 |
168 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public boolean onTouchEvent(MotionEvent e) {
169 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
170 | if (e.getActionMasked() == MotionEvent.ACTION_DOWN) {
171 | if (foreground != null) {
172 | foreground.setHotspot(e.getX(), e.getY());
173 | }
174 | }
175 | }
176 | return super.onTouchEvent(e);
177 | }
178 | }
179 |
--------------------------------------------------------------------------------
/foregroundviews/src/main/java/com/cesards/android/foregroundviews/ForegroundLinearLayout.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 DogmaLabs
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.cesards.android.foregroundviews;
18 |
19 | import android.annotation.TargetApi;
20 | import android.content.Context;
21 | import android.content.res.TypedArray;
22 | import android.graphics.Canvas;
23 | import android.graphics.Rect;
24 | import android.graphics.drawable.Drawable;
25 | import android.graphics.drawable.NinePatchDrawable;
26 | import android.os.Build;
27 | import android.util.AttributeSet;
28 | import android.view.MotionEvent;
29 | import android.widget.LinearLayout;
30 |
31 | public class ForegroundLinearLayout extends LinearLayout {
32 |
33 | // UI
34 | private Drawable foreground;
35 |
36 | // Controller/logic fields
37 | private final Rect rectPadding = new Rect();
38 | private boolean foregroundPadding = false;
39 | private boolean foregroundBoundsChanged = false;
40 | private boolean backgroundAsForeground = false;
41 |
42 | // Constructors
43 | public ForegroundLinearLayout(Context context) {
44 | super(context);
45 | }
46 |
47 | public ForegroundLinearLayout(Context context, AttributeSet attrs) {
48 | this(context, attrs, 0);
49 | }
50 |
51 | public ForegroundLinearLayout(Context context, AttributeSet attrs, int defStyle) {
52 | super(context, attrs, defStyle);
53 |
54 | final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundLayout, defStyle, 0);
55 |
56 | final Drawable d = a.getDrawable(R.styleable.ForegroundLayout_foreground);
57 | foregroundPadding = a.getBoolean(R.styleable.ForegroundLayout_foregroundInsidePadding, false);
58 |
59 | backgroundAsForeground = a.getBoolean(R.styleable.ForegroundLayout_backgroundAsForeground, false);
60 |
61 | // Apply foreground padding for ninepatches automatically
62 | if (!foregroundPadding && getBackground() instanceof NinePatchDrawable) {
63 | final NinePatchDrawable npd = (NinePatchDrawable) getBackground();
64 | if (npd != null && npd.getPadding(rectPadding)) {
65 | foregroundPadding = true;
66 | }
67 | }
68 |
69 | final Drawable b = getBackground();
70 | if (backgroundAsForeground && b != null) {
71 | setForeground(b);
72 | } else if (d != null) {
73 | setForeground(d);
74 | }
75 |
76 | a.recycle();
77 | }
78 |
79 | /**
80 | * Supply a Drawable that is to be rendered on top of all of the child views in the layout.
81 | *
82 | * @param drawable The Drawable to be drawn on top of the children.
83 | */
84 | public void setForeground(Drawable drawable) {
85 | if (foreground != drawable) {
86 | if (foreground != null) {
87 | foreground.setCallback(null);
88 | unscheduleDrawable(foreground);
89 | }
90 |
91 | foreground = drawable;
92 |
93 | if (drawable != null) {
94 | setWillNotDraw(false);
95 | drawable.setCallback(this);
96 | if (drawable.isStateful()) {
97 | drawable.setState(getDrawableState());
98 | }
99 | } else {
100 | setWillNotDraw(true);
101 | }
102 | requestLayout();
103 | invalidate();
104 | }
105 | }
106 |
107 | /**
108 | * Returns the drawable used as the foreground of this layout. The foreground drawable,
109 | * if non-null, is always drawn on top of the children.
110 | *
111 | * @return A Drawable or null if no foreground was set.
112 | */
113 | public Drawable getForeground() {
114 | return foreground;
115 | }
116 |
117 | @Override
118 | protected void drawableStateChanged() {
119 | super.drawableStateChanged();
120 |
121 | if (foreground != null && foreground.isStateful()) {
122 | foreground.setState(getDrawableState());
123 | }
124 | }
125 |
126 | @Override
127 | protected boolean verifyDrawable(Drawable who) {
128 | return super.verifyDrawable(who) || (who == foreground);
129 | }
130 |
131 | @Override
132 | public void jumpDrawablesToCurrentState() {
133 | super.jumpDrawablesToCurrentState();
134 |
135 | if (foreground != null) {
136 | foreground.jumpToCurrentState();
137 | }
138 | }
139 |
140 | @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) {
141 | super.onSizeChanged(w, h, oldw, oldh);
142 | foregroundBoundsChanged = true;
143 | }
144 |
145 | @Override
146 | public void draw(Canvas canvas) {
147 | super.draw(canvas);
148 |
149 | if (foreground != null) {
150 | final Drawable foreground = this.foreground;
151 |
152 | if (foregroundBoundsChanged) {
153 | foregroundBoundsChanged = false;
154 |
155 | final int w = getRight() - getLeft();
156 | final int h = getBottom() - getTop();
157 |
158 | if (foregroundPadding) {
159 | foreground.setBounds(rectPadding.left, rectPadding.top, w - rectPadding.right, h - rectPadding.bottom);
160 | } else {
161 | foreground.setBounds(0, 0, w, h);
162 | }
163 | }
164 | foreground.draw(canvas);
165 | }
166 | }
167 |
168 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public boolean onTouchEvent(MotionEvent e) {
169 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
170 | if (e.getActionMasked() == MotionEvent.ACTION_DOWN) {
171 | if (foreground != null) {
172 | foreground.setHotspot(e.getX(), e.getY());
173 | }
174 | }
175 | }
176 | return super.onTouchEvent(e);
177 | }
178 |
179 | }
180 |
--------------------------------------------------------------------------------
/foregroundviews/src/main/java/com/cesards/android/foregroundviews/ForegroundRelativeLayout.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 DogmaLabs
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package com.cesards.android.foregroundviews;
18 |
19 | import android.annotation.TargetApi;
20 | import android.content.Context;
21 | import android.content.res.TypedArray;
22 | import android.graphics.Canvas;
23 | import android.graphics.Rect;
24 | import android.graphics.drawable.Drawable;
25 | import android.graphics.drawable.NinePatchDrawable;
26 | import android.os.Build;
27 | import android.util.AttributeSet;
28 | import android.view.MotionEvent;
29 | import android.widget.RelativeLayout;
30 |
31 | public class ForegroundRelativeLayout extends RelativeLayout {
32 |
33 | // UI
34 | private Drawable foreground;
35 |
36 | // Controller/logic fields
37 | private final Rect rectPadding = new Rect();
38 | private boolean foregroundPadding = false;
39 | private boolean foregroundBoundsChanged = false;
40 | private boolean backgroundAsForeground = false;
41 |
42 | // Constructors
43 | public ForegroundRelativeLayout(Context context) {
44 | super(context);
45 | }
46 |
47 | public ForegroundRelativeLayout(Context context, AttributeSet attrs) {
48 | this(context, attrs, 0);
49 | }
50 |
51 | public ForegroundRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
52 | super(context, attrs, defStyle);
53 |
54 | final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundLayout, defStyle, 0);
55 |
56 | final Drawable d = a.getDrawable(R.styleable.ForegroundLayout_foreground);
57 | foregroundPadding = a.getBoolean(R.styleable.ForegroundLayout_foregroundInsidePadding, false);
58 |
59 | backgroundAsForeground = a.getBoolean(R.styleable.ForegroundLayout_backgroundAsForeground, false);
60 |
61 | // Apply foreground padding for ninepatches automatically
62 | if (!foregroundPadding && getBackground() instanceof NinePatchDrawable) {
63 | final NinePatchDrawable npd = (NinePatchDrawable) getBackground();
64 | if (npd != null && npd.getPadding(rectPadding)) {
65 | foregroundPadding = true;
66 | }
67 | }
68 |
69 | final Drawable b = getBackground();
70 | if (backgroundAsForeground && b != null) {
71 | setForeground(b);
72 | } else if (d != null) {
73 | setForeground(d);
74 | }
75 |
76 | a.recycle();
77 | }
78 |
79 | /**
80 | * Supply a Drawable that is to be rendered on top of all of the child views in the layout.
81 | *
82 | * @param drawable The Drawable to be drawn on top of the children.
83 | */
84 | public void setForeground(Drawable drawable) {
85 | if (foreground != drawable) {
86 | if (foreground != null) {
87 | foreground.setCallback(null);
88 | unscheduleDrawable(foreground);
89 | }
90 |
91 | foreground = drawable;
92 |
93 | if (drawable != null) {
94 | setWillNotDraw(false);
95 | drawable.setCallback(this);
96 | if (drawable.isStateful()) {
97 | drawable.setState(getDrawableState());
98 | }
99 | } else {
100 | setWillNotDraw(true);
101 | }
102 | requestLayout();
103 | invalidate();
104 | }
105 | }
106 |
107 | /**
108 | * Returns the drawable used as the foreground of this layout. The foreground drawable,
109 | * if non-null, is always drawn on top of the children.
110 | *
111 | * @return A Drawable or null if no foreground was set.
112 | */
113 | public Drawable getForeground() {
114 | return foreground;
115 | }
116 |
117 | @Override
118 | protected void drawableStateChanged() {
119 | super.drawableStateChanged();
120 |
121 | if (foreground != null && foreground.isStateful()) {
122 | foreground.setState(getDrawableState());
123 | }
124 | }
125 |
126 | @Override
127 | protected boolean verifyDrawable(Drawable who) {
128 | return super.verifyDrawable(who) || (who == foreground);
129 | }
130 |
131 | @Override
132 | public void jumpDrawablesToCurrentState() {
133 | super.jumpDrawablesToCurrentState();
134 |
135 | if (foreground != null) {
136 | foreground.jumpToCurrentState();
137 | }
138 | }
139 |
140 | @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) {
141 | super.onSizeChanged(w, h, oldw, oldh);
142 | foregroundBoundsChanged = true;
143 | }
144 |
145 | @Override
146 | public void draw(Canvas canvas) {
147 | super.draw(canvas);
148 |
149 | if (foreground != null) {
150 | final Drawable foreground = this.foreground;
151 |
152 | if (foregroundBoundsChanged) {
153 | foregroundBoundsChanged = false;
154 |
155 | final int w = getRight() - getLeft();
156 | final int h = getBottom() - getTop();
157 |
158 | if (foregroundPadding) {
159 | foreground.setBounds(rectPadding.left, rectPadding.top, w - rectPadding.right, h - rectPadding.bottom);
160 | } else {
161 | foreground.setBounds(0, 0, w, h);
162 | }
163 | }
164 | foreground.draw(canvas);
165 | }
166 | }
167 |
168 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public boolean onTouchEvent(MotionEvent e) {
169 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
170 | if (e.getActionMasked() == MotionEvent.ACTION_DOWN) {
171 | if (foreground != null) {
172 | foreground.setHotspot(e.getX(), e.getY());
173 | }
174 | }
175 | }
176 | return super.onTouchEvent(e);
177 | }
178 |
179 | }
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
--------------------------------------------------------------------------------
/foregroundviews/src/main/java/com/cesards/android/foregroundviews/ForegroundImageView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2014 DogmaLabs
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.cesards.android.foregroundviews;
17 |
18 | import android.annotation.TargetApi;
19 | import android.content.Context;
20 | import android.content.res.TypedArray;
21 | import android.graphics.Canvas;
22 | import android.graphics.Rect;
23 | import android.graphics.drawable.Drawable;
24 | import android.graphics.drawable.NinePatchDrawable;
25 | import android.os.Build;
26 | import android.util.AttributeSet;
27 | import android.view.MotionEvent;
28 | import android.widget.ImageView;
29 |
30 | public class ForegroundImageView extends ImageView {
31 |
32 | // UI
33 | private Drawable foreground;
34 |
35 | // Controller/logic fields
36 | private final Rect rectPadding = new Rect();
37 | private boolean foregroundPadding = false;
38 | private boolean foregroundBoundsChanged = false;
39 | private boolean backgroundAsForeground = false;
40 |
41 | // Constructors
42 | public ForegroundImageView(Context context) {
43 | super(context);
44 | }
45 |
46 | public ForegroundImageView(Context context, AttributeSet attrs) {
47 | this(context, attrs, 0);
48 | }
49 |
50 | public ForegroundImageView(Context context, AttributeSet attrs, int defStyle) {
51 | super(context, attrs, defStyle);
52 |
53 | final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ForegroundLayout, defStyle, 0);
54 |
55 | final Drawable d = a.getDrawable(R.styleable.ForegroundLayout_foreground);
56 | foregroundPadding = a.getBoolean(R.styleable.ForegroundLayout_foregroundInsidePadding, false);
57 |
58 | backgroundAsForeground = a.getBoolean(R.styleable.ForegroundLayout_backgroundAsForeground, false);
59 |
60 | // Apply foreground padding for ninepatches automatically
61 | if (!foregroundPadding && getBackground() instanceof NinePatchDrawable) {
62 | final NinePatchDrawable npd = (NinePatchDrawable) getBackground();
63 | if (npd != null && npd.getPadding(rectPadding)) {
64 | foregroundPadding = true;
65 | }
66 | }
67 |
68 | final Drawable b = getBackground();
69 | if (backgroundAsForeground && b != null) {
70 | setForeground(b);
71 | } else if (d != null) {
72 | setForeground(d);
73 | }
74 |
75 | a.recycle();
76 | }
77 |
78 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) public ForegroundImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
79 | super(context, attrs, defStyleAttr, defStyleRes);
80 | }
81 |
82 | /**
83 | * Supply a Drawable that is to be rendered on top of all of the child views in the layout.
84 | *
85 | * @param drawable The Drawable to be drawn on top of the children.
86 | */
87 | public void setForeground(Drawable drawable) {
88 | if (foreground != drawable) {
89 | if (foreground != null) {
90 | foreground.setCallback(null);
91 | unscheduleDrawable(foreground);
92 | }
93 |
94 | foreground = drawable;
95 |
96 | if (drawable != null) {
97 | setWillNotDraw(false);
98 | drawable.setCallback(this);
99 | if (drawable.isStateful()) {
100 | drawable.setState(getDrawableState());
101 | }
102 | } else {
103 | setWillNotDraw(true);
104 | }
105 | requestLayout();
106 | invalidate();
107 | }
108 | }
109 |
110 | /**
111 | * Returns the drawable used as the foreground of this layout. The foreground drawable,
112 | * if non-null, is always drawn on top of the children.
113 | *
114 | * @return A Drawable or null if no foreground was set.
115 | */
116 | public Drawable getForeground() {
117 | return foreground;
118 | }
119 |
120 | @Override
121 | protected void drawableStateChanged() {
122 | super.drawableStateChanged();
123 |
124 | if (foreground != null && foreground.isStateful()) {
125 | foreground.setState(getDrawableState());
126 | }
127 | }
128 |
129 | @Override
130 | protected boolean verifyDrawable(Drawable who) {
131 | return super.verifyDrawable(who) || (who == foreground);
132 | }
133 |
134 | @Override
135 | public void jumpDrawablesToCurrentState() {
136 | super.jumpDrawablesToCurrentState();
137 |
138 | if (foreground != null) {
139 | foreground.jumpToCurrentState();
140 | }
141 | }
142 |
143 | @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) {
144 | super.onSizeChanged(w, h, oldw, oldh);
145 | foregroundBoundsChanged = true;
146 | }
147 |
148 | @Override
149 | public void draw(Canvas canvas) {
150 | super.draw(canvas);
151 |
152 | if (foreground != null) {
153 | final Drawable foreground = this.foreground;
154 |
155 | if (foregroundBoundsChanged) {
156 | foregroundBoundsChanged = false;
157 |
158 | final int w = getRight() - getLeft();
159 | final int h = getBottom() - getTop();
160 |
161 | if (foregroundPadding) {
162 | foreground.setBounds(rectPadding.left, rectPadding.top, w - rectPadding.right, h - rectPadding.bottom);
163 | } else {
164 | foreground.setBounds(0, 0, w, h);
165 | }
166 | }
167 | foreground.draw(canvas);
168 | }
169 | }
170 |
171 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public boolean onTouchEvent(MotionEvent e) {
172 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
173 | if (e.getActionMasked() == MotionEvent.ACTION_DOWN) {
174 | if (foreground != null) {
175 | foreground.setHotspot(e.getX(), e.getY());
176 | }
177 | }
178 | }
179 | return super.onTouchEvent(e);
180 | }
181 |
182 | }
183 |
184 |
--------------------------------------------------------------------------------
/codestyles_DogmaLabs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2015 César Díez Sánchez
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------