Skip to content

Commit 52faae3

Browse files
committed
add process example
1 parent 850f359 commit 52faae3

39 files changed

+1289
-4
lines changed

Example/.idea/gradle.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/.idea/modules.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ buildscript {
99

1010
// NOTE: Do not place your application dependencies here; they belong
1111
// in the individual module build.gradle files
12-
}
13-
14-
dependencies {
1512
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
1613
}
14+
1715
}
1816

1917
allprojects {

Example/commonlib/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@ dependencies {
3333

3434
compile 'io.reactivex:rxjava:1.1.6'
3535
compile 'io.reactivex:rxandroid:1.2.1'
36+
3637
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.geek.commonlib.utils;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.os.Bundle;
7+
8+
9+
public class UIUtils {
10+
public static void startActivity(Context context, Class<?> cls) {
11+
Intent intent = new Intent();
12+
intent.setClass(context, cls);
13+
context.startActivity(intent);
14+
}
15+
16+
public static void startActivity(Context context, Class<?> cls,
17+
Bundle bundle) {
18+
19+
if (context instanceof Activity){
20+
Intent intent = new Intent();
21+
intent.setClass(context, cls);
22+
intent.putExtras(bundle);
23+
context.startActivity(intent);
24+
}else{
25+
startActivityByApplication(context , cls , bundle);
26+
}
27+
28+
}
29+
public static void startActivityByApplication(Context context, Class<?> cls,
30+
Bundle bundle) {
31+
Intent intent = new Intent();
32+
intent.setClass(context, cls);
33+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
34+
intent.putExtras(bundle);
35+
context.startActivity(intent);
36+
}
37+
38+
public static void closeActivity(Context context) {
39+
((Activity) context).finish();
40+
}
41+
}

Example/processexample/.gitignore

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

Example/processexample/build.gradle

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 24
5+
buildToolsVersion "24.0.2"
6+
7+
defaultConfig {
8+
applicationId "com.rayootech.www.processexample"
9+
minSdkVersion 14
10+
targetSdkVersion 24
11+
versionCode 1
12+
versionName "1.0"
13+
14+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15+
16+
vectorDrawables.useSupportLibrary = true
17+
}
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22+
}
23+
}
24+
}
25+
26+
dependencies {
27+
compile fileTree(include: ['*.jar'], dir: 'libs')
28+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
29+
exclude group: 'com.android.support', module: 'support-annotations'
30+
})
31+
compile 'com.android.support:appcompat-v7:24.2.1'
32+
compile 'com.android.support:design:24.2.1'
33+
compile 'com.android.support:support-v4:24.2.1'
34+
compile 'com.android.support:support-vector-drawable:24.2.1'
35+
testCompile 'junit:junit:4.12'
36+
compile project(':commonlib')
37+
}
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 /Users/zhanggeng/android_tools/android_studio/android-sdk-macosx/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+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.rayootech.www.processexample;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumentation test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.rayootech.www.processexample", appContext.getPackageName());
25+
}
26+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.rayootech.www.processexample">
4+
5+
<!-- To auto-complete the email text field in the login form with the user's emails -->
6+
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
7+
<uses-permission android:name="android.permission.READ_PROFILE" />
8+
<uses-permission android:name="android.permission.READ_CONTACTS" />
9+
10+
<application
11+
android:allowBackup="true"
12+
android:icon="@mipmap/ic_launcher"
13+
android:name=".MyApplication"
14+
android:label="@string/app_name"
15+
android:supportsRtl="true"
16+
android:theme="@style/AppTheme">
17+
<activity android:name=".MainActivity">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN" />
20+
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
</activity>
24+
<activity
25+
android:name=".LoginActivity"
26+
android:process=":yes"
27+
android:label="@string/title_activity_login" />
28+
<activity
29+
android:name=".FullscreenActivity"
30+
android:process="com.rayootech.www.processexample.yes"
31+
android:configChanges="orientation|keyboardHidden|screenSize"
32+
android:label="@string/title_activity_fullscreen"
33+
android:theme="@style/FullscreenTheme"></activity>
34+
</application>
35+
36+
</manifest>
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
package com.rayootech.www.processexample;
2+
3+
import android.annotation.SuppressLint;
4+
import android.support.v7.app.ActionBar;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.os.Bundle;
7+
import android.os.Handler;
8+
import android.view.MotionEvent;
9+
import android.view.View;
10+
11+
/**
12+
* An example full-screen activity that shows and hides the system UI (i.e.
13+
* status bar and navigation/system bar) with user interaction.
14+
*/
15+
public class FullscreenActivity extends AppCompatActivity {
16+
/**
17+
* Whether or not the system UI should be auto-hidden after
18+
* {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
19+
*/
20+
private static final boolean AUTO_HIDE = true;
21+
22+
/**
23+
* If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
24+
* user interaction before hiding the system UI.
25+
*/
26+
private static final int AUTO_HIDE_DELAY_MILLIS = 3000;
27+
28+
/**
29+
* Some older devices needs a small delay between UI widget updates
30+
* and a change of the status and navigation bar.
31+
*/
32+
private static final int UI_ANIMATION_DELAY = 300;
33+
private final Handler mHideHandler = new Handler();
34+
private View mContentView;
35+
private final Runnable mHidePart2Runnable = new Runnable() {
36+
@SuppressLint("InlinedApi")
37+
@Override
38+
public void run() {
39+
// Delayed removal of status and navigation bar
40+
41+
// Note that some of these constants are new as of API 16 (Jelly Bean)
42+
// and API 19 (KitKat). It is safe to use them, as they are inlined
43+
// at compile-time and do nothing on earlier devices.
44+
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
45+
| View.SYSTEM_UI_FLAG_FULLSCREEN
46+
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
47+
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
48+
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
49+
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
50+
}
51+
};
52+
private View mControlsView;
53+
private final Runnable mShowPart2Runnable = new Runnable() {
54+
@Override
55+
public void run() {
56+
// Delayed display of UI elements
57+
ActionBar actionBar = getSupportActionBar();
58+
if (actionBar != null) {
59+
actionBar.show();
60+
}
61+
mControlsView.setVisibility(View.VISIBLE);
62+
}
63+
};
64+
private boolean mVisible;
65+
private final Runnable mHideRunnable = new Runnable() {
66+
@Override
67+
public void run() {
68+
hide();
69+
}
70+
};
71+
/**
72+
* Touch listener to use for in-layout UI controls to delay hiding the
73+
* system UI. This is to prevent the jarring behavior of controls going away
74+
* while interacting with activity UI.
75+
*/
76+
private final View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
77+
@Override
78+
public boolean onTouch(View view, MotionEvent motionEvent) {
79+
if (AUTO_HIDE) {
80+
delayedHide(AUTO_HIDE_DELAY_MILLIS);
81+
}
82+
return false;
83+
}
84+
};
85+
86+
@Override
87+
protected void onCreate(Bundle savedInstanceState) {
88+
super.onCreate(savedInstanceState);
89+
90+
setContentView(R.layout.activity_fullscreen);
91+
92+
mVisible = true;
93+
mControlsView = findViewById(R.id.fullscreen_content_controls);
94+
mContentView = findViewById(R.id.fullscreen_content);
95+
96+
97+
// Set up the user interaction to manually show or hide the system UI.
98+
mContentView.setOnClickListener(new View.OnClickListener() {
99+
@Override
100+
public void onClick(View view) {
101+
toggle();
102+
}
103+
});
104+
105+
// Upon interacting with UI controls, delay any scheduled hide()
106+
// operations to prevent the jarring behavior of controls going away
107+
// while interacting with the UI.
108+
findViewById(R.id.dummy_button).setOnTouchListener(mDelayHideTouchListener);
109+
}
110+
111+
@Override
112+
protected void onPostCreate(Bundle savedInstanceState) {
113+
super.onPostCreate(savedInstanceState);
114+
115+
// Trigger the initial hide() shortly after the activity has been
116+
// created, to briefly hint to the user that UI controls
117+
// are available.
118+
delayedHide(100);
119+
}
120+
121+
private void toggle() {
122+
if (mVisible) {
123+
hide();
124+
} else {
125+
show();
126+
}
127+
}
128+
129+
private void hide() {
130+
// Hide UI first
131+
ActionBar actionBar = getSupportActionBar();
132+
if (actionBar != null) {
133+
actionBar.hide();
134+
}
135+
mControlsView.setVisibility(View.GONE);
136+
mVisible = false;
137+
138+
// Schedule a runnable to remove the status and navigation bar after a delay
139+
mHideHandler.removeCallbacks(mShowPart2Runnable);
140+
mHideHandler.postDelayed(mHidePart2Runnable, UI_ANIMATION_DELAY);
141+
}
142+
143+
@SuppressLint("InlinedApi")
144+
private void show() {
145+
// Show the system bar
146+
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
147+
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
148+
mVisible = true;
149+
150+
// Schedule a runnable to display UI elements after a delay
151+
mHideHandler.removeCallbacks(mHidePart2Runnable);
152+
mHideHandler.postDelayed(mShowPart2Runnable, UI_ANIMATION_DELAY);
153+
}
154+
155+
/**
156+
* Schedules a call to hide() in [delay] milliseconds, canceling any
157+
* previously scheduled calls.
158+
*/
159+
private void delayedHide(int delayMillis) {
160+
mHideHandler.removeCallbacks(mHideRunnable);
161+
mHideHandler.postDelayed(mHideRunnable, delayMillis);
162+
}
163+
}

0 commit comments

Comments
 (0)