forked from mubai-wu/MockLauncherOverlay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
79 changed files
with
2,415 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.iml | ||
.gradle | ||
.idea | ||
/local.properties | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 28 | ||
defaultConfig { | ||
applicationId "com.wbh.mock.launcher" | ||
minSdkVersion 23 | ||
targetSdkVersion 28 | ||
versionCode 1 | ||
versionName "1.0" | ||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation fileTree(dir: 'libs', include: ['*.jar']) | ||
implementation 'com.android.support:appcompat-v7:28.0.0' | ||
implementation 'com.android.support.constraint:constraint-layout:1.1.3' | ||
testImplementation 'junit:junit:4.12' | ||
androidTestImplementation 'com.android.support.test:runner:1.0.2' | ||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# 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 *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
26 changes: 26 additions & 0 deletions
26
MockLauncher/app/src/androidTest/java/com/wbh/mock/launcher/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.wbh.mock.launcher; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
import android.support.test.runner.AndroidJUnit4; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | ||
*/ | ||
@RunWith(AndroidJUnit4.class) | ||
public class ExampleInstrumentedTest { | ||
@Test | ||
public void useAppContext() { | ||
// Context of the app under test. | ||
Context appContext = InstrumentationRegistry.getTargetContext(); | ||
|
||
assertEquals("com.wbh.mock.launcher", appContext.getPackageName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.wbh.mock.launcher"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".mainactivity.view.LauncherActivity" | ||
android:theme="@style/Theme.AppCompat.NoActionBar"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
42 changes: 42 additions & 0 deletions
42
...ncher/app/src/main/aidl/com/google/android/libraries/launcherclient/ILauncherOverlay.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.google.android.libraries.launcherclient; | ||
|
||
import android.view.WindowManager.LayoutParams; | ||
import com.google.android.libraries.launcherclient.ILauncherOverlayCallback; | ||
|
||
interface ILauncherOverlay { | ||
|
||
oneway void startScroll(); | ||
|
||
oneway void onScroll(in float progress); | ||
|
||
oneway void endScroll(); | ||
|
||
oneway void windowAttached(in LayoutParams lp, in ILauncherOverlayCallback cb, in int flags); | ||
|
||
oneway void windowDetached(in boolean isChangingConfigurations); | ||
|
||
oneway void closeOverlay(in int flags); | ||
|
||
oneway void onPause(); | ||
|
||
oneway void onResume(); | ||
|
||
oneway void openOverlay(in int flags); | ||
|
||
oneway void requestVoiceDetection(in boolean start); | ||
|
||
String getVoiceSearchLanguage(); | ||
|
||
boolean isVoiceDetectionRunning(); | ||
|
||
boolean hasOverlayContent(); | ||
|
||
oneway void windowAttached2(in Bundle bundle, in ILauncherOverlayCallback cb); | ||
|
||
oneway void unusedMethod(); | ||
|
||
oneway void setActivityState(in int flags); | ||
|
||
boolean startSearch(in byte[] data, in Bundle bundle); | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...p/src/main/aidl/com/google/android/libraries/launcherclient/ILauncherOverlayCallback.aidl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.google.android.libraries.launcherclient; | ||
|
||
interface ILauncherOverlayCallback { | ||
|
||
oneway void overlayScrollChanged(float progress); | ||
|
||
oneway void overlayStatusChanged(int status); | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
MockLauncher/app/src/main/java/com/wbh/mock/launcher/mainactivity/model/ILauncherModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.wbh.mock.launcher.mainactivity.model; | ||
|
||
import android.content.Context; | ||
import android.view.WindowManager; | ||
|
||
public interface ILauncherModel { | ||
void bindService(Context context); | ||
void startScrollOverlay(); | ||
void showOverlayProgress(float progress); | ||
void endScrollOverlay(); | ||
void setOverlayWindowParams(WindowManager.LayoutParams layoutParams); | ||
} |
117 changes: 117 additions & 0 deletions
117
...auncher/app/src/main/java/com/wbh/mock/launcher/mainactivity/model/LauncherModelImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.wbh.mock.launcher.mainactivity.model; | ||
|
||
import android.content.ComponentName; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.ServiceConnection; | ||
import android.os.IBinder; | ||
import android.os.RemoteException; | ||
import android.view.WindowManager; | ||
|
||
import com.google.android.libraries.launcherclient.ILauncherOverlay; | ||
import com.google.android.libraries.launcherclient.ILauncherOverlayCallback; | ||
import com.wbh.mock.launcher.mainactivity.presenter.ILauncherPresenter; | ||
|
||
public class LauncherModelImpl implements ILauncherModel { | ||
|
||
private final static String OVERLAY_PACKAGE_NAME = "com.wbh.mock.overlay"; | ||
private final static String OVERLAY_SERVICE_ACTION = "com.wbh.mock.overlay.MockService"; | ||
|
||
private ILauncherPresenter mILauncherPresenter; | ||
private ILauncherOverlay mILauncherOverlay; | ||
|
||
private boolean mIsServiceConnected; | ||
private boolean mIsOverlayWindowAttached; | ||
|
||
private WindowManager.LayoutParams mLayoutParams; | ||
|
||
public LauncherModelImpl(ILauncherPresenter presenter) { | ||
mILauncherPresenter = presenter; | ||
} | ||
|
||
@Override | ||
public void bindService(Context context) { | ||
if (mIsServiceConnected) { | ||
return; | ||
} | ||
Intent intent = new Intent(OVERLAY_SERVICE_ACTION); | ||
intent.setPackage(OVERLAY_PACKAGE_NAME); | ||
context.bindService(intent, new ServiceConnection() { | ||
@Override | ||
public void onServiceConnected(ComponentName name, IBinder service) { | ||
mIsServiceConnected = true; | ||
mILauncherOverlay = ILauncherOverlay.Stub.asInterface(service); | ||
} | ||
|
||
@Override | ||
public void onServiceDisconnected(ComponentName name) { | ||
mIsServiceConnected = false; | ||
} | ||
}, Context.BIND_AUTO_CREATE); | ||
|
||
} | ||
|
||
@Override | ||
public void startScrollOverlay() { | ||
try { | ||
attachOverlayWindowIfNeed(mLayoutParams); | ||
if (mILauncherOverlay != null) { | ||
mILauncherOverlay.startScroll(); | ||
} | ||
} catch (RemoteException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void showOverlayProgress(float progress) { | ||
try { | ||
if (mILauncherOverlay != null) { | ||
mILauncherOverlay.onScroll(progress); | ||
} | ||
} catch (RemoteException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void endScrollOverlay() { | ||
try { | ||
if (mILauncherOverlay != null) { | ||
mILauncherOverlay.endScroll(); | ||
} | ||
} catch (RemoteException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public void setOverlayWindowParams(WindowManager.LayoutParams layoutParams) { | ||
mLayoutParams = layoutParams; | ||
} | ||
|
||
private void attachOverlayWindowIfNeed(WindowManager.LayoutParams layoutParams) { | ||
if (mIsOverlayWindowAttached) { | ||
return; | ||
} | ||
try { | ||
if (mILauncherOverlay != null && layoutParams != null) { | ||
mILauncherOverlay.windowAttached(layoutParams, new ILauncherOverlayCallback.Stub() { | ||
@Override | ||
public void overlayScrollChanged(float progress) { | ||
mILauncherPresenter.onOverlayScroll(progress); | ||
} | ||
|
||
@Override | ||
public void overlayStatusChanged(int status) { | ||
|
||
} | ||
}, 1 | 2 | 4 | 8); | ||
mIsOverlayWindowAttached = true; | ||
} | ||
} catch (RemoteException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...er/app/src/main/java/com/wbh/mock/launcher/mainactivity/presenter/ILauncherPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.wbh.mock.launcher.mainactivity.presenter; | ||
|
||
import android.app.Activity; | ||
import android.view.View; | ||
|
||
public interface ILauncherPresenter { | ||
|
||
// --- call by view | ||
void onClick(View view); | ||
|
||
void startScroll(); | ||
void onScroll(View view, int scrollX); | ||
void endScroll(); | ||
|
||
void onCreate(Activity activity); | ||
|
||
// --- call by model | ||
|
||
void onOverlayScroll(float progress); | ||
} |
63 changes: 63 additions & 0 deletions
63
...app/src/main/java/com/wbh/mock/launcher/mainactivity/presenter/LauncherPresenterImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.wbh.mock.launcher.mainactivity.presenter; | ||
|
||
import android.app.Activity; | ||
import android.view.View; | ||
|
||
import com.wbh.mock.launcher.mainactivity.model.ILauncherModel; | ||
import com.wbh.mock.launcher.mainactivity.model.LauncherModelImpl; | ||
import com.wbh.mock.launcher.mainactivity.view.ILauncherView; | ||
|
||
public class LauncherPresenterImpl implements ILauncherPresenter { | ||
|
||
private ILauncherView mILauncherView; | ||
private ILauncherModel mILauncherModel; | ||
private boolean mStartedSendingScrollEvents; | ||
private boolean mIsUserSlideLauncher = false; | ||
|
||
public LauncherPresenterImpl(ILauncherView iLauncherView) { | ||
mILauncherView = iLauncherView; | ||
mILauncherModel = new LauncherModelImpl(this); | ||
} | ||
|
||
@Override | ||
public void onClick(View view) { | ||
mILauncherModel.bindService(view.getContext()); | ||
} | ||
|
||
@Override | ||
public void startScroll() { | ||
mIsUserSlideLauncher = true; | ||
} | ||
|
||
@Override | ||
public void onScroll(View view, int scrollX) { | ||
boolean shouldScrollOverlay = scrollX <= 0; | ||
if (shouldScrollOverlay && mIsUserSlideLauncher) { | ||
if (!mStartedSendingScrollEvents) { | ||
mILauncherModel.startScrollOverlay(); | ||
mStartedSendingScrollEvents = true; | ||
} | ||
mILauncherModel.showOverlayProgress(-scrollX * 1.0f / view.getMeasuredWidth()); | ||
} | ||
} | ||
|
||
@Override | ||
public void endScroll() { | ||
mIsUserSlideLauncher = false; | ||
if (mStartedSendingScrollEvents){ | ||
mILauncherModel.endScrollOverlay(); | ||
mStartedSendingScrollEvents = false; | ||
} | ||
} | ||
|
||
@Override | ||
public void onCreate(Activity activity) { | ||
mILauncherModel.setOverlayWindowParams(activity.getWindow().getAttributes()); | ||
} | ||
|
||
@Override | ||
public void onOverlayScroll(float progress) { | ||
mILauncherView.showNegativePage(1 - progress); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
MockLauncher/app/src/main/java/com/wbh/mock/launcher/mainactivity/view/ILauncherView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.wbh.mock.launcher.mainactivity.view; | ||
|
||
import android.app.Activity; | ||
|
||
public interface ILauncherView { | ||
Activity getActivity(); | ||
|
||
void showNegativePage(float progress); | ||
} |
Oops, something went wrong.