/images/avatar.png

^_^

Android 事件处理机制

事件处理

https://img-blog.csdnimg.cn/20200319125011916.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzM3Njk3,size_16,color_FFFFFF,t_70 https://img-blog.csdnimg.cn/20200319125041979.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzM3Njk3,size_16,color_FFFFFF,t_70 https://img-blog.csdnimg.cn/20200319125148988.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzM3Njk3,size_16,color_FFFFFF,t_70

基于监听的事件处理机制

匿名内部类

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
mbt1.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()){
                    case MotionEvent.ACTION_DOWN:
                        Log.d("listener","touch");
                        break;
                }
                return false;
            }
        });

事件源所在类(activity类)

1
public class eventActivity extends AppCompatActivity implements View.OnClickListener
1
2
ebt1 = findViewById(R.id.ebt1);
        ebt1.setOnClickListener(eventActivity.this);
1
2
3
4
5
6
7
8
@Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.ebt1:
                Toast.makeText(eventActivity.this , "click...",Toast.LENGTH_LONG).show();
                break;
        }
    }

在布局文件中设置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<Button
        android:id="@+id/ebt1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="click"
        android:textSize="20sp"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="50dp"
        android:onClick="show"
        />
1
2
3
4
5
6
7
public void show(View view){             //一定是public void
        switch (view.getId()){
            case R.id.ebt1:
                Toast.makeText(eventActivity.this , "click...",Toast.LENGTH_LONG).show();
                break;
        }
    }

https://img-blog.csdnimg.cn/20200319131750142.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzM3Njk3,size_16,color_FFFFFF,t_70

Android 四大组件之Activity

Activity

https://img-blog.csdnimg.cn/2020031908390495.PNG https://img-blog.csdnimg.cn/20200319083947645.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzM3Njk3,size_16,color_FFFFFF,t_70 https://img-blog.csdnimg.cn/20200319084012872.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzM3Njk3,size_16,color_FFFFFF,t_70

activity的生命周期

https://img-blog.csdnimg.cn/20200318214923967.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzM3Njk3,size_16,color_FFFFFF,t_70

运行以下代码可以看到activity经历的生命周期

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.example.test;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

public class lifeCircleActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_life_circle);
        Log.d("lifecircle","-----onCreate----");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d("lifecircle","-----onStart----");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d("lifecircle","-----onResume----");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d("lifecircle","-----onPause----");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d("lifecircle","-----onStop----");
    }

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d("lifecircle","-----onRestart----");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("lifecircle","-----onDestroy----");
    }

}

启动这个activity之后

Android 四大组件之Content Provider

Content Provider

https://img-blog.csdnimg.cn/20200319153118615.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzM3Njk3,size_16,color_FFFFFF,t_70 https://img-blog.csdnimg.cn/20200319153232133.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzM3Njk3,size_16,color_FFFFFF,t_70 https://img-blog.csdnimg.cn/20200319153348737.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzM3Njk3,size_16,color_FFFFFF,t_70 https://img-blog.csdnimg.cn/20200319153425979.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzM3Njk3,size_16,color_FFFFFF,t_70 https://img-blog.csdnimg.cn/20200319153505783.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzM3Njk3,size_16,color_FFFFFF,t_70 https://img-blog.csdnimg.cn/20200319153534803.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzM3Njk3,size_16,color_FFFFFF,t_70

获取外部应用的信息

以获取通讯录为例

布局文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".contentProviderActivity">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/cpbtn1"
        android:textSize="25sp"
        android:text="get_contacts"/>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/cpbtn2"
        android:text="getdata"
        android:textSize="25dp"
        app:layout_constraintTop_toBottomOf="@+id/cpbtn1"
        android:layout_marginTop="20dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

点击get_contacts获取联系人信息

hduoj1711(kmp)

Number Sequence

Problem Description

Given two sequences of numbers : a[1], a[2], …… , a[N], and b[1], b[2], …… , b[M] (1 <= M <= 10000, 1 <= N <= 1000000). Your task is to find a number K which make a[K] = b[1], a[K + 1] = b[2], …… , a[K + M - 1] = b[M]. If there are more than one K exist, output the smallest one.

Codeforces Round #628 (Div. 2) A~D

A. EhAb AnD gCd

题意

给一正整数x,求正整数a,b满足gcd(a,b)+lcm(a,b)=x

题解

数论思维题,a=1,b=x-1满足条件

ac代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#include<iostream>
using namespace std;
int main(){
    int t;
    cin>>t;
    while(t--) {
        int k;
        cin>>k;
        cout<<1<<" "<<k-1<<endl;
    }
    return 0;
}

B. CopyCopyCopyCopyCopy

题意

给一数列,将数列无限复制,求最长严格单调子序列的个数

二进制编码

二进制转十进制

除2取余

十进制转二进制

乘2次幂

小数进制转换

e.g.

3.59375

整数部分3的二进制位11

小数部分0.59375

0.59375*2=1.1875 ———————— 1

0.1875*2=0.375 —————————0

0.375*2=0.75 ——————————0

0.75*2=1.5 ——————————–1

0.5*2=1 ———————————–1

二进制位0.10011

所以3.59375的二进制表示为11.10011

Codeforces Round #627 (Div. 3)

A. Yet Another Tetris Problem link

B. Yet Another Palindrome Problem link

C. Frog Jumps link

D. Pair of Topics link

E. Sleeping Schedule link

题意

假设一天有h个小时,DIO一共要睡n次,每次睡ai个小时(按顺序睡觉),每次刚睡醒,就要继续睡觉,一直睡下去,直至睡眠次数耗光。

ef - a tale of melodies

《ef - a tale of melodies.》由日本动画公司SHAFT制作电视动画,并于2008年10月6日开始播放,是动画《悠久之翼》系列的第二季。故事内容由原作游戏《ef - the latter tale.》的第四章及终章改篇而成,终章的修改幅度比较大,加入了一些原创的情节。共12话。

abc158

A - Station and Bus

题目链接

题意

给一长度为3的,只含AB的字符串,问是否存在相邻两个字符不同的情况

题解

签到题

ac代码

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if((s[0]=='A' and s[1]=='A' and s[2]=='A') or(s[0]=='B' and s[1]=='B' and s[2]=='B'))
	cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

B - Count Balls

题目链接

题意

有蓝球和红球若干,将他们排成一排,不断通过以下操作排列,在尾部加a个蓝球,在尾部加b个红球,问前n个球有多少个蓝球

波斯王子

波斯王子 prince of persia是ubisoft于1989年发行的一款单机游戏 https://img-blog.csdnimg.cn/20200308225600498.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQzNzM3Njk3,size_16,color_FFFFFF,t_70 波斯王子有好多部,前3部是一个完整的故事,后面则是一些衍生