GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 添加互相吊起的service · tmexcept/AndroidCustomView@400e389

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .idea
    • compiler.xml
    • misc.xml
  • app/src/main
    • AndroidManifest.xml
    • java/com/allen/android
      • activity
        • MainActivity.kt
      • service
        • CheckService.java
        • KeepLifeService.java
      • widget
        • GradientAlphaView.java
    • res/layout
      • activity_animation_btn.xml
  • build.gradle
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.idea/compiler.xml‎

Copy file name to clipboardExpand all lines: .idea/compiler.xml
+1-1Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎.idea/misc.xml‎

Copy file name to clipboardExpand all lines: .idea/misc.xml
+1-1Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎app/src/main/AndroidManifest.xml‎

Copy file name to clipboardExpand all lines: app/src/main/AndroidManifest.xml
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
<activity android:name="com.allen.android.stretch.StretchPagerTestActivity" />
4646
<activity android:name="com.allen.android.coordinatorzoom.CoordinatorZoomActivity" />
4747
<activity android:name="com.allen.android.coordinatorzoom.PullZoomRecyclerActivity" />
48+
49+
50+
<service android:name=".service.KeepLifeService"
51+
android:process=":keepLife" />
52+
<service android:name=".service.CheckService"
53+
android:process=":keepLife" />
4854
</application>
4955

5056
</manifest>
Collapse file

‎app/src/main/java/com/allen/android/activity/MainActivity.kt‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/allen/android/activity/MainActivity.kt
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import com.allen.android.coordinatorzoom.CoordinatorZoomActivity
1414
import com.allen.android.coordinatorzoom.PullZoomRecyclerActivity
1515
import com.allen.android.gradient.GradientActivity
1616
import com.allen.android.helper.DragViewHelper
17+
import com.allen.android.service.CheckService
18+
import com.allen.android.service.KeepLifeService
1719
import com.allen.android.stretch.StretchPagerTestActivity
1820
import com.allen.android.tagview.TagActivity
1921
import com.allen.android.widget.SuperDividerItemDecoration
2022
import com.chad.library.adapter.base.BaseQuickAdapter
2123
import kotlinx.android.synthetic.main.activity_main.*
22-
import java.util.*
2324

2425

2526
class MainActivity : AppCompatActivity(), BaseQuickAdapter.OnItemClickListener {
@@ -36,7 +37,7 @@ class MainActivity : AppCompatActivity(), BaseQuickAdapter.OnItemClickListener {
3637
typeBeans.add(TypeBean("波浪动画--正余弦函数实现", index++))
3738
typeBeans.add(TypeBean("水波(雷达)扩散效果", index++))
3839
typeBeans.add(TypeBean("RecyclerView实现另类的Tag标签", index++))
39-
typeBeans.add(TypeBean("按钮自定义动画", index++))
40+
typeBeans.add(TypeBean("按钮自定义动画、图片部分透明度渐变动画", index++))
4041
typeBeans.add(TypeBean("自定义支付密码输入框", index++))
4142
typeBeans.add(TypeBean("自定义进度条", index++))
4243
typeBeans.add(TypeBean("使用的带动画的view", index++))
@@ -76,6 +77,8 @@ class MainActivity : AppCompatActivity(), BaseQuickAdapter.OnItemClickListener {
7677
onClick = {
7778
Toast.makeText(this, "点击事件", Toast.LENGTH_SHORT).show()
7879
})
80+
81+
startService(Intent(this, CheckService::class.java))
7982
}
8083

8184
override fun onItemClick(adapter: BaseQuickAdapter<*, *>, view: View, position: Int) {
Collapse file

‎app/src/main/java/com/allen/android/service/CheckService.java‎

Copy file name to clipboard
+86Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.allen.android.service;
2+
3+
import android.app.ActivityManager;
4+
import android.app.Service;
5+
import android.content.Intent;
6+
import android.os.Handler;
7+
import android.os.IBinder;
8+
import android.os.Message;
9+
10+
import com.allen.android.utils.LogX;
11+
12+
import java.util.List;
13+
import java.util.Timer;
14+
import java.util.TimerTask;
15+
16+
public class CheckService extends Service {
17+
private static final String PackageName = "com.****.****";
18+
private final Timer timerMail = new Timer();
19+
private ActivityManager activityManager=null;
20+
21+
@Override
22+
public IBinder onBind(Intent arg0) {
23+
return null;
24+
}
25+
26+
@Override
27+
public void onCreate() {
28+
LogX.e(" 开启检查服务" );
29+
timerMail.schedule(new TimerTask() {
30+
@Override
31+
public void run() {
32+
LogX.e(" 发送消息");
33+
Message message = new Message();
34+
message.what = 1;
35+
mHandler.sendMessage(message);
36+
}
37+
}, 15000, 5000);
38+
super.onCreate();
39+
}
40+
41+
private Handler mHandler = new Handler(new Handler.Callback() {
42+
@Override
43+
public boolean handleMessage(Message msg) {
44+
try {
45+
if(!isBackgroundRunning()){
46+
LogX.e(" 退出操作");
47+
logout();
48+
}
49+
} catch (Exception e) {
50+
e.printStackTrace();
51+
}
52+
return false;
53+
}
54+
});
55+
56+
private boolean isBackgroundRunning() {
57+
activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
58+
if (activityManager == null) {
59+
return false;
60+
}
61+
List<ActivityManager.RunningTaskInfo> processList = activityManager.getRunningTasks(100);
62+
for (ActivityManager.RunningTaskInfo info : processList) {
63+
if (info.baseActivity.getPackageName().startsWith(PackageName)) {
64+
return true;
65+
}
66+
}
67+
return false;
68+
}
69+
70+
/* (non-Javadoc)
71+
* @see android.app.Service#onDestroy()
72+
*/
73+
@Override
74+
public void onDestroy() {
75+
if (timerMail!= null){
76+
timerMail.cancel();
77+
}
78+
LogX.e(" 销毁服务");
79+
super.onDestroy();
80+
}
81+
82+
public void logout() {
83+
84+
}
85+
}
86+
Collapse file

‎app/src/main/java/com/allen/android/service/KeepLifeService.java‎

Copy file name to clipboard
+95Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.allen.android.service;
2+
3+
import android.app.ActivityManager;
4+
import android.app.Service;
5+
import android.content.Context;
6+
import android.content.Intent;
7+
import android.os.IBinder;
8+
import android.support.annotation.Nullable;
9+
import android.text.TextUtils;
10+
import android.util.Log;
11+
12+
import java.io.BufferedReader;
13+
import java.io.File;
14+
import java.io.FileReader;
15+
import java.util.List;
16+
17+
public class KeepLifeService extends Service {
18+
19+
private static final String TAG="KeepLifeService";
20+
21+
private String mPackName;
22+
private ActivityManager mActivityManager;
23+
24+
@Override
25+
public void onCreate() {
26+
super.onCreate();
27+
mActivityManager =(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
28+
29+
String process=getProcessName();
30+
mPackName =getPackageName();
31+
32+
boolean isRun=isRunningProcess(mActivityManager,mPackName);
33+
Log.i(TAG, String.format("onCreate: %s %s pid=%d uid=%d isRun=%s", mPackName,process,
34+
11, 10/*Process.myPid(), Process.myUid()*/,isRun));
35+
36+
if(!isRun){
37+
Intent intent = getPackageManager().getLaunchIntentForPackage(mPackName);
38+
if(intent!=null){
39+
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
40+
startActivity(intent);
41+
}
42+
}
43+
44+
}
45+
46+
@Override
47+
public int onStartCommand(Intent intent, int flags, int startId) {
48+
super.onStartCommand(intent, flags, startId);
49+
return START_STICKY;
50+
}
51+
52+
@Nullable
53+
@Override
54+
public IBinder onBind(Intent intent) {
55+
return null;
56+
}
57+
58+
/**
59+
* 获取当前进程名称
60+
*
61+
* @return
62+
*/
63+
public static String getProcessName() {
64+
try {
65+
File file = new File("/proc/" + android.os.Process.myPid() + "/" + "cmdline");
66+
BufferedReader mBufferedReader = new BufferedReader(new FileReader(file));
67+
String processName = mBufferedReader.readLine().trim();
68+
mBufferedReader.close();
69+
return processName;
70+
} catch (Exception e) {
71+
e.printStackTrace();
72+
return null;
73+
}
74+
}
75+
76+
77+
/**
78+
* 进程是否存活
79+
* @return
80+
*/
81+
public static boolean isRunningProcess(ActivityManager manager, String processName) {
82+
if(manager==null)
83+
return false;
84+
List<ActivityManager.RunningAppProcessInfo> runnings = manager.getRunningAppProcesses();
85+
if (runnings != null) {
86+
for (ActivityManager.RunningAppProcessInfo info : runnings) {
87+
if(TextUtils.equals(info.processName,processName)){
88+
return true;
89+
}
90+
}
91+
}
92+
return false;
93+
}
94+
95+
}
Collapse file

‎app/src/main/java/com/allen/android/widget/GradientAlphaView.java‎

Copy file name to clipboard
+89Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.allen.android.widget;
2+
3+
import android.content.Context;
4+
import android.graphics.Bitmap;
5+
import android.graphics.BitmapFactory;
6+
import android.graphics.Canvas;
7+
import android.graphics.Color;
8+
import android.graphics.LinearGradient;
9+
import android.graphics.Paint;
10+
import android.graphics.PorterDuff;
11+
import android.graphics.PorterDuffXfermode;
12+
import android.graphics.RectF;
13+
import android.graphics.Shader;
14+
import android.support.annotation.Nullable;
15+
import android.util.AttributeSet;
16+
import android.view.View;
17+
import android.widget.ImageView;
18+
19+
import com.allen.android.R;
20+
import com.allen.android.utils.ScreenTools;
21+
22+
public class GradientAlphaView extends ImageView {
23+
public GradientAlphaView(Context context) {
24+
this(context, null);
25+
}
26+
27+
public GradientAlphaView(Context context, @Nullable AttributeSet attrs) {
28+
this(context, attrs, 0);
29+
}
30+
31+
Paint mPaint;
32+
public GradientAlphaView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
33+
super(context, attrs, defStyleAttr);
34+
35+
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
36+
mPaint.setDither(true);
37+
38+
width = ScreenTools.dip2px(100);
39+
height = ScreenTools.dip2px(50);
40+
41+
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
42+
int colors[] = {Color.TRANSPARENT, 0x55ffffff, 0x00ff0000};
43+
float pos[] = {0, width/4, width/2};
44+
mPaint.setShader(new LinearGradient(0, 0, width, 0,
45+
colors, null, Shader.TileMode.CLAMP));
46+
47+
rectF = new RectF(0, 0, 0, 0);
48+
btnBg = BitmapFactory.decodeResource(
49+
getResources(), R.mipmap.wheel_big_btn_bg, null);
50+
}
51+
Bitmap btnBg;
52+
int width, height;
53+
RectF rectF;
54+
55+
@Override
56+
protected void onDraw(Canvas canvas) {
57+
// rectF.set(0, 0, btnBg.getWidth(), btnBg.getHeight());
58+
// Paint p = new Paint();
59+
// p.setColor(Color.YELLOW);
60+
// p.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
61+
// p.setShader(new LinearGradient(0, 0, btnBg.getWidth() * 0.5f, 0,
62+
// Color.TRANSPARENT, Color.RED, Shader.TileMode.CLAMP));
63+
// int saved = canvas.saveLayer(rectF, p, Canvas.ALL_SAVE_FLAG);
64+
// canvas.drawBitmap(btnBg, 0, 0, new Paint());
65+
// canvas.drawPaint(p);
66+
// canvas.restoreToCount(saved);
67+
68+
69+
rectF.set(0, 0, getWidth(), getHeight());
70+
int saved = canvas.saveLayer(rectF, mPaint, Canvas.ALL_SAVE_FLAG);
71+
super.onDraw(canvas);
72+
// canvas.clipRect(0,0, width, getHeight());
73+
canvas.drawPaint(mPaint);
74+
canvas.restoreToCount(saved);
75+
}
76+
77+
private float mProgress;
78+
private Paint getAlphaPaint(int imageW, int imageH) {
79+
Paint paint = new Paint();
80+
if (mProgress > 0f && mProgress < 0.2f) {
81+
paint.setShader(new LinearGradient(0, imageH / 2, imageW * mProgress, imageH / 2,
82+
Color.TRANSPARENT, Color.BLACK, Shader.TileMode.CLAMP));
83+
} else {
84+
paint.setShader(new LinearGradient(0, imageH / 2, imageW / 5, imageH / 2,
85+
Color.TRANSPARENT, Color.BLACK, Shader.TileMode.CLAMP));
86+
}
87+
return paint;
88+
}
89+
}
Collapse file

‎app/src/main/res/layout/activity_animation_btn.xml‎

Copy file name to clipboardExpand all lines: app/src/main/res/layout/activity_animation_btn.xml
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33
android:layout_width="match_parent"
44
android:layout_height="match_parent"
55
android:layout_gravity="center"
6-
android:gravity="center">
6+
android:gravity="center"
7+
android:orientation="vertical"
8+
android:background="@color/aliPay_bar_color">
79

810
<com.allen.android.widget.AnimationButton
911
android:id="@+id/animation_btn"
1012
android:layout_width="200dp"
1113
android:layout_height="50dp" />
1214

15+
<com.allen.android.widget.GradientAlphaView
16+
android:layout_marginTop="50dp"
17+
android:layout_width="200dp"
18+
android:layout_height="200dp"
19+
android:background="#66ffffff"/>
20+
1321
</LinearLayout>
Collapse file

‎build.gradle‎

Copy file name to clipboardExpand all lines: build.gradle
+6-12Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
buildscript {
44
ext.kotlin_version = '1.3.20'
55
repositories {
6-
google()
7-
jcenter()
8-
maven {
9-
url 'https://maven.google.com/'
10-
name 'Google'
11-
}
6+
maven { url 'https://maven.aliyun.com/repository/google' }
7+
maven { url 'https://maven.aliyun.com/repository/central' }
8+
maven { url "https://maven.aliyun.com/repository/releases" }
129
}
1310
dependencies {
1411
classpath 'com.android.tools.build:gradle:3.4.2'
@@ -21,13 +18,10 @@ buildscript {
2118

2219
allprojects {
2320
repositories {
24-
google()
25-
jcenter()
21+
maven { url 'https://maven.aliyun.com/repository/google' }
22+
maven { url 'https://maven.aliyun.com/repository/central' }
23+
maven { url "https://maven.aliyun.com/repository/releases" }
2624
maven { url "https://jitpack.io" }
27-
maven {
28-
url 'https://maven.google.com/'
29-
name 'Google'
30-
}
3125
}
3226
}
3327

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.