Skip to content

Commit

Permalink
add floating logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Xlythe committed Nov 12, 2016
1 parent b1121e3 commit 35faf06
Show file tree
Hide file tree
Showing 41 changed files with 1,259 additions and 46 deletions.
59 changes: 13 additions & 46 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,47 +1,14 @@
# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# =========================
# Operating System Files
# =========================

# OSX
# =========================

.gradle
/.gradle
/gradle
/.idea
gradlew.bat
gradlew
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
/build
*.iml
local.properties
*.apk
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# FloatingView

Quick and simple library for creating floating views and activities

License:

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

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.
4 changes: 4 additions & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/build
*.iml
manifest-merger-release-report.txt
*.apk
31 changes: 31 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apply plugin: 'com.android.application'

repositories {
jcenter()
}

android {
compileSdkVersion 25
buildToolsVersion "24.0.3"

defaultConfig {
applicationId "com.xlythe.view.floating.sample"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
}
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':floating-view')
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:recyclerview-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
}
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:\Program Files (x86)\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 *;
#}
38 changes: 38 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xlythe.view.floating.sample">

<!-- For floating calculator -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.VIBRATE" />

<application
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
<activity
android:name=".CreateActivity"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.CREATE_SHORTCUT" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".OpenActivity"
android:excludeFromRecents="true"
android:exported="true"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:theme="@style/TransparentBackground">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".FloatingNotes" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.xlythe.view.floating.sample;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;

/**
* Creates the shortcut icon
*/
public class CreateActivity extends Activity {
private static final int REQUEST_CODE_WINDOW_OVERLAY_PERMISSION = 10001;

public void onCreate(Bundle state) {
super.onCreate(state);

if (Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
if (android.os.Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(this)) {
startActivityForResult(
new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())),
REQUEST_CODE_WINDOW_OVERLAY_PERMISSION);
} else {
onSuccess();
}
}
}

private void onSuccess() {
Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher);

Intent intent = new Intent();
Intent launchIntent = new Intent(this, OpenActivity.class);

intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

setResult(RESULT_OK, intent);
finish();
}

private void onFailure() {
setResult(RESULT_CANCELED);
finish();
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_WINDOW_OVERLAY_PERMISSION) {
if (Build.VERSION.SDK_INT >= 23 && Settings.canDrawOverlays(this)) {
onSuccess();
} else {
onFailure();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.xlythe.view.floating.sample;

import android.graphics.Point;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.xlythe.view.floating.FloatingView;

public class FloatingNotes extends FloatingView {
@NonNull
@Override
public View inflateButton(@NonNull ViewGroup parent) {
return LayoutInflater.from(getContext()).inflate(R.layout.floating_icon, parent, false);
}

@NonNull
@Override
public View inflateView(@NonNull ViewGroup parent) {
return LayoutInflater.from(getContext()).inflate(R.layout.floating_notes, parent, false);
}

@Override
public void onShow() {

}

@Override
public void onHide() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.xlythe.view.floating.sample;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;

/**
* When the shortcut icon is pressed, use this Activity to launch the overlay Service
*/
public class OpenActivity extends Activity {
private static final int REQUEST_CODE_WINDOW_OVERLAY_PERMISSION = 10001;

public void onCreate(Bundle state) {
super.onCreate(state);

if (android.os.Build.VERSION.SDK_INT >= 23 && !Settings.canDrawOverlays(this)) {
startActivityForResult(
new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())),
REQUEST_CODE_WINDOW_OVERLAY_PERMISSION);
} else {
onSuccess();
}
}

private void onSuccess() {
Intent intent = new Intent(this, FloatingNotes.class);
startService(intent);
finish();
}

private void onFailure() {
setResult(RESULT_CANCELED);
finish();
}

@Override
public void finish() {
super.finish();
overridePendingTransition(R.anim.blank, R.anim.blank);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_WINDOW_OVERLAY_PERMISSION) {
if (android.os.Build.VERSION.SDK_INT >= 23 && Settings.canDrawOverlays(this)) {
onSuccess();
} else {
onFailure();
}
}
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/layout/floating_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="65dp"
android:layout_height="65dp"
android:src="@mipmap/ic_launcher" />
12 changes: 12 additions & 0 deletions app/src/main/res/layout/floating_notes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="150dp"
android:layout_height="400dp"
android:orientation="vertical"
android:background="#3000fff0">

<TextView
android:text="Hello World"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</LinearLayout>
Binary file added app/src/main/res/mipmap-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 app/src/main/res/mipmap-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 app/src/main/res/mipmap-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 app/src/main/res/mipmap-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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">Floating Notes</string>
</resources>
11 changes: 11 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="TransparentBackground">
<item name="android:windowFrame">@null</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowAnimationStyle">@null</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">false</item>
</style>
</resources>
19 changes: 19 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
jcenter()
}
}
2 changes: 2 additions & 0 deletions floating-view/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
*.iml
Loading

0 comments on commit 35faf06

Please sign in to comment.