Skip to content

Commit

Permalink
upload code firstly
Browse files Browse the repository at this point in the history
  • Loading branch information
mubai-wu committed Jan 12, 2020
1 parent 4d8f763 commit 1722a86
Show file tree
Hide file tree
Showing 79 changed files with 2,415 additions and 0 deletions.
8 changes: 8 additions & 0 deletions MockLauncher/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.iml
.gradle
.idea
/local.properties
.DS_Store
/build
/captures
.externalNativeBuild
1 change: 1 addition & 0 deletions MockLauncher/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
28 changes: 28 additions & 0 deletions MockLauncher/app/build.gradle
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'
}
21 changes: 21 additions & 0 deletions MockLauncher/app/proguard-rules.pro
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
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());
}
}
22 changes: 22 additions & 0 deletions MockLauncher/app/src/main/AndroidManifest.xml
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>
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);

}
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);

}
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);
}
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();
}
}
}
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);
}
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);
}

}
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);
}
Loading

0 comments on commit 1722a86

Please sign in to comment.