Skip to content
This repository was archived by the owner on Jun 26, 2022. It is now read-only.

Commit 70b41af

Browse files
committed
init project
0 parents  commit 70b41af

File tree

32 files changed

+1459
-0
lines changed

32 files changed

+1459
-0
lines changed

.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
lt application files
2+
*.apk
3+
*.ap_
4+
5+
# Files for the Dalvik VM
6+
*.dex
7+
8+
# Java class files
9+
*.class
10+
11+
# Generated files
12+
bin/
13+
gen/
14+
out/
15+
16+
# Gradle files
17+
.gradle/
18+
build/
19+
20+
# Local configuration file (sdk path, etc)
21+
local.properties
22+
23+
# Proguard folder generated by Eclipse
24+
proguard/
25+
26+
# Log Files
27+
*.log
28+
29+
# Android Studio Navigation editor temp files
30+
.navigation/
31+
32+
# Android Studio captures folder
33+
captures/
34+
35+
# Intellij
36+
*.iml
37+
38+
# Keystore files
39+
*.jks*.iml
40+
41+
.idea/

LICENSE.txt

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "24.0.0 rc3"
6+
7+
defaultConfig {
8+
applicationId "org.kslr.moonlight"
9+
minSdkVersion 14
10+
targetSdkVersion 23
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
testCompile 'junit:junit:4.12'
25+
compile 'com.android.support:appcompat-v7:23.3.0'
26+
compile 'com.google.android.gms:play-services:8.4.0'
27+
compile 'com.google.android.gms:play-services-analytics:8.4.0'
28+
}
29+
30+
apply plugin: 'com.google.gms.google-services'

app/google-services.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"project_info": {
3+
"project_number": "360323118733",
4+
"project_id": "moonlight-6b6e8"
5+
},
6+
"client": [
7+
{
8+
"client_info": {
9+
"mobilesdk_app_id": "1:360323118733:android:95f4f9a122b66046",
10+
"android_client_info": {
11+
"package_name": "org.kslr.moonlight"
12+
}
13+
},
14+
"oauth_client": [],
15+
"api_key": [
16+
{
17+
"current_key": "AIzaSyCkqFs5_xwONYMq9-DWCi0PdljMZfp6h0M"
18+
}
19+
],
20+
"services": {
21+
"analytics_service": {
22+
"status": 2,
23+
"analytics_property": {
24+
"tracking_id": "UA-28741729-11"
25+
}
26+
},
27+
"appinvite_service": {
28+
"status": 1,
29+
"other_platform_oauth_client": []
30+
},
31+
"ads_service": {
32+
"status": 1
33+
}
34+
}
35+
}
36+
],
37+
"configuration_version": "1"
38+
}

app/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /home/kslr/Android/Sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.kslr.moonlight;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}

app/src/main/AndroidManifest.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="org.kslr.moonlight">
4+
5+
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
6+
<uses-permission android:name="permission.permission.SYSTEM_OVERLAY_WINDOW" />
7+
<uses-permission android:name="android.permission.INTERNET"/>
8+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
9+
<!-- Get permission for reliable local dispatching on non-Google Play devices. -->
10+
<uses-permission android:name="android.permission.WAKE_LOCK" />
11+
12+
<application
13+
android:name=".MyApplication"
14+
android:allowBackup="true"
15+
android:icon="@mipmap/ic_launcher"
16+
android:label="@string/app_name"
17+
android:supportsRtl="true"
18+
android:theme="@style/AppTheme">
19+
<activity android:name=".MainActivity">
20+
<intent-filter>
21+
<action android:name="android.intent.action.MAIN" />
22+
23+
<category android:name="android.intent.category.LAUNCHER" />
24+
</intent-filter>
25+
</activity>
26+
27+
<!-- Register AnalyticsReceiver and AnalyticsService to support background
28+
dispatching on non-Google Play devices. -->
29+
<receiver android:name="com.google.android.gms.analytics.CampaignTrackingReceiver"
30+
android:enabled="true"
31+
android:exported="true">
32+
<intent-filter>
33+
<action android:name="com.android.vending.INSTALL_REFERRER" />
34+
</intent-filter>
35+
</receiver>
36+
<service android:name="com.google.android.gms.analytics.CampaignTrackingService" />
37+
<receiver android:name="com.google.android.gms.analytics.AnalyticsReceiver"
38+
android:enabled="true">
39+
<intent-filter>
40+
<action android:name="com.google.android.gms.analytics.ANALYTICS_DISPATCH" />
41+
</intent-filter>
42+
</receiver>
43+
<service android:name="com.google.android.gms.analytics.AnalyticsService"
44+
android:enabled="true"
45+
android:exported="false"/>
46+
47+
<!-- ... -->
48+
</application>
49+
</manifest>
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
package org.kslr.moonlight;
2+
3+
import android.content.Context;
4+
import android.content.Intent;
5+
import android.graphics.Color;
6+
import android.graphics.PixelFormat;
7+
import android.net.Uri;
8+
import android.support.v7.app.AppCompatActivity;
9+
import android.os.Bundle;
10+
import android.view.MotionEvent;
11+
import android.view.View;
12+
import android.view.ViewGroup;
13+
import android.view.Window;
14+
import android.view.WindowManager;
15+
import android.widget.Button;
16+
import android.widget.SeekBar;
17+
import android.widget.TextView;
18+
19+
import com.google.android.gms.analytics.Tracker;
20+
21+
22+
public class MainActivity extends AppCompatActivity {
23+
24+
private TextView mFeedback;
25+
private TextView mProgress;
26+
private SeekBar mSeekBar;
27+
private TextView mLayout;
28+
private Float mAlpha = 0.9f;
29+
private Button mRunController;
30+
private Boolean mRunMark = true;
31+
private WindowManager mWindowManager;
32+
33+
@Override
34+
protected void onCreate(Bundle savedInstanceState) {
35+
super.onCreate(savedInstanceState);
36+
setContentView(R.layout.activity_main);
37+
// 初始化悬浮遮罩层
38+
mLayout = new TextView(getApplicationContext());
39+
// 初始化窗口服务
40+
mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
41+
// 初始化Google统计
42+
MyApplication application = (MyApplication) getApplication();
43+
Tracker mTracker = application.getDefaultTracker();
44+
// 滑动条
45+
mSeekBar = (SeekBar) findViewById(R.id.seekBar);
46+
mSeekBar.setOnSeekBarChangeListener(seekListener);
47+
// 控制器按钮
48+
mRunController = (Button) findViewById(R.id.button);
49+
mRunController.setOnClickListener(buttonListener);
50+
// 第一次打开的时候自动打开开关
51+
buttonListener.onClick(null);
52+
// 监听屏幕全屏动作
53+
mLayout.setOnTouchListener(touchListener);
54+
// 反馈
55+
mFeedback = (TextView) findViewById(R.id.feedback);
56+
mFeedback.setOnClickListener(new View.OnClickListener() {
57+
@Override
58+
public void onClick(View v) {
59+
Intent mail = new Intent(Intent.ACTION_SENDTO);
60+
mail.setData(Uri.parse("mailto:[email protected]"));
61+
mail.putExtra(Intent.EXTRA_SUBJECT, "Moonlight Feedback");
62+
startActivity(mail);
63+
}
64+
});
65+
}
66+
67+
/**
68+
* 控制器监听器
69+
*/
70+
private View.OnClickListener buttonListener = new View.OnClickListener() {
71+
@Override
72+
public void onClick(View v) {
73+
if (mRunMark) {
74+
// 关闭状态,准备启动
75+
startNight();
76+
mSeekBar.setProgress(90);
77+
mRunController.setText(R.string.app_button_off);
78+
mRunMark = false;
79+
} else {
80+
// 启动状态,准备关闭
81+
stopNight();
82+
mSeekBar.setProgress(0);
83+
mRunController.setText(R.string.app_buttion_on);
84+
mRunMark = true;
85+
}
86+
}
87+
};
88+
89+
/**
90+
* 启动遮罩层
91+
*/
92+
public void startNight() {
93+
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
94+
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
95+
WindowManager.LayoutParams.TYPE_TOAST
96+
, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
97+
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
98+
| WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
99+
PixelFormat.TRANSLUCENT
100+
);
101+
lp.x = 0;
102+
lp.y = 0;
103+
lp.alpha = mAlpha;
104+
mLayout.setBackgroundColor(Color.BLACK);
105+
mWindowManager.addView(mLayout, lp);
106+
}
107+
108+
/**
109+
* 删除遮罩层
110+
*/
111+
public void stopNight() {
112+
mWindowManager.removeView(mLayout);
113+
}
114+
115+
private View.OnTouchListener touchListener = new View.OnTouchListener() {
116+
@Override
117+
public boolean onTouch(View v, MotionEvent event) {
118+
Window window = getWindow();
119+
int location[] = new int[2];
120+
v.getLocationOnScreen(location);
121+
System.out.println(location);
122+
return true;
123+
}
124+
};
125+
126+
// public boolean onTouchListener() {
127+
// Window window = getWindow();
128+
129+
// if(isFullScreen){
130+
// //设置非全屏
131+
// window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
132+
//
133+
// }else{
134+
// //设置全屏
135+
// window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
136+
// }
137+
// isFullScreen = !isFullScreen;
138+
// return true;
139+
// }
140+
141+
private SeekBar.OnSeekBarChangeListener seekListener = new SeekBar.OnSeekBarChangeListener() {
142+
@Override
143+
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
144+
if(mLayout != null) {
145+
// 最高只能到90
146+
if(progress <= 90) {
147+
mLayout.setAlpha((float) (progress / 100.0));
148+
}
149+
mProgress = (TextView) findViewById(R.id.progress);
150+
mProgress.setText(progress + "%");
151+
}
152+
}
153+
154+
@Override
155+
public void onStartTrackingTouch(SeekBar seekBar) {
156+
157+
}
158+
159+
@Override
160+
public void onStopTrackingTouch(SeekBar seekBar) {
161+
162+
}
163+
};
164+
165+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.kslr.moonlight;
2+
3+
import android.app.Application;
4+
5+
import com.google.android.gms.analytics.GoogleAnalytics;
6+
import com.google.android.gms.analytics.Tracker;
7+
8+
/**
9+
* Created by kslr on 16-4-24.
10+
*/
11+
public class MyApplication extends Application {
12+
13+
private Tracker mTracker;
14+
15+
/**
16+
* Gets the default {@link Tracker} for this {@link Application}.
17+
* @return tracker
18+
*/
19+
synchronized public Tracker getDefaultTracker() {
20+
if (mTracker == null) {
21+
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
22+
mTracker = analytics.newTracker(R.xml.global_tracker);
23+
mTracker.enableExceptionReporting(true);
24+
}
25+
return mTracker;
26+
}
27+
28+
}

0 commit comments

Comments
 (0)