├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── drawable-xxhdpi
│ │ │ │ └── ic_clear_blue.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── activity_main.xml
│ │ │ │ └── call_popup_top.xml
│ │ ├── java
│ │ │ └── gun0912
│ │ │ │ └── com
│ │ │ │ └── incomingcallmarketbroadcastreceiver
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── IncomingCallBroadcastReceiver.java
│ │ │ │ └── CallingService.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── gun0912
│ │ │ └── com
│ │ │ └── incomingcallmarketbroadcastreceiver
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── gun0912
│ │ └── com
│ │ └── incomingcallmarketbroadcastreceiver
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── README.md
└── .idea
└── vcs.xml
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # IncomingCallMarketBroadcastReceiver
2 |
3 | http://gun0912.tistory.com/46
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | IncomingCallMarketBroadcastReceiver
3 |
4 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/IncomingCallMarketBroadcastReceiver/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/IncomingCallMarketBroadcastReceiver/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/IncomingCallMarketBroadcastReceiver/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/IncomingCallMarketBroadcastReceiver/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/IncomingCallMarketBroadcastReceiver/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_clear_blue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ParkSangGwon/IncomingCallMarketBroadcastReceiver/HEAD/app/src/main/res/drawable-xxhdpi/ic_clear_blue.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/gun0912/com/incomingcallmarketbroadcastreceiver/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package gun0912.com.incomingcallmarketbroadcastreceiver;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/java/gun0912/com/incomingcallmarketbroadcastreceiver/MainActivity.java:
--------------------------------------------------------------------------------
1 | package gun0912.com.incomingcallmarketbroadcastreceiver;
2 |
3 | import android.support.v7.app.AppCompatActivity;
4 | import android.os.Bundle;
5 |
6 | public class MainActivity extends AppCompatActivity {
7 |
8 | @Override
9 | protected void onCreate(Bundle savedInstanceState) {
10 | super.onCreate(savedInstanceState);
11 | setContentView(R.layout.activity_main);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/gun0912/com/incomingcallmarketbroadcastreceiver/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package gun0912.com.incomingcallmarketbroadcastreceiver;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/TedPark/Library/Android/sdk/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 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.2"
6 |
7 | defaultConfig {
8 | applicationId "gun0912.com.incomingcallmarketbroadcastreceiver"
9 | minSdkVersion 14
10 | targetSdkVersion 23
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | testCompile 'junit:junit:4.12'
25 | compile 'com.android.support:appcompat-v7:23.1.1'
26 |
27 |
28 | compile 'com.jakewharton:butterknife:6.1.0'
29 |
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/call_popup_top.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
12 |
13 |
21 |
22 |
23 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/java/gun0912/com/incomingcallmarketbroadcastreceiver/IncomingCallBroadcastReceiver.java:
--------------------------------------------------------------------------------
1 | package gun0912.com.incomingcallmarketbroadcastreceiver;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.os.Handler;
7 | import android.os.Looper;
8 | import android.telephony.PhoneNumberUtils;
9 | import android.telephony.TelephonyManager;
10 | import android.util.Log;
11 |
12 | /**
13 | * Created by TedPark on 15. 12. 10..
14 | */
15 | public class IncomingCallBroadcastReceiver extends BroadcastReceiver {
16 |
17 | public static final String TAG = "PHONE STATE";
18 | private static String mLastState;
19 |
20 | private final Handler mHandler = new Handler(Looper.getMainLooper());
21 |
22 |
23 | @Override
24 | public void onReceive(final Context context, Intent intent) {
25 | Log.d(TAG,"onReceive()");
26 |
27 |
28 | /**
29 | * http://mmarvick.github.io/blog/blog/lollipop-multiple-broadcastreceiver-call-state/
30 | * 2번 호출되는 문제 해결
31 | */
32 | String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
33 |
34 | if (state.equals(mLastState)) {
35 | return;
36 |
37 | } else {
38 | mLastState = state;
39 |
40 | }
41 |
42 |
43 | if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)) {
44 | String incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
45 | final String phone_number = PhoneNumberUtils.formatNumber(incomingNumber);
46 |
47 | Intent serviceIntent = new Intent(context, CallingService.class);
48 | serviceIntent.putExtra(CallingService.EXTRA_CALL_NUMBER, phone_number);
49 | context.startService(serviceIntent);
50 |
51 | }
52 |
53 |
54 |
55 | }
56 |
57 |
58 | }
--------------------------------------------------------------------------------
/app/src/main/java/gun0912/com/incomingcallmarketbroadcastreceiver/CallingService.java:
--------------------------------------------------------------------------------
1 | package gun0912.com.incomingcallmarketbroadcastreceiver;
2 |
3 | import android.app.Service;
4 | import android.content.Intent;
5 | import android.graphics.PixelFormat;
6 | import android.os.IBinder;
7 | import android.text.TextUtils;
8 | import android.view.Display;
9 | import android.view.LayoutInflater;
10 | import android.view.MotionEvent;
11 | import android.view.View;
12 | import android.view.WindowManager;
13 | import android.widget.TextView;
14 |
15 | import butterknife.ButterKnife;
16 | import butterknife.InjectView;
17 | import butterknife.OnClick;
18 |
19 | /**
20 | * Created by TedPark on 15. 12. 15..
21 | */
22 | public class CallingService extends Service {
23 |
24 | public static final String EXTRA_CALL_NUMBER = "call_number";
25 | protected View rootView;
26 |
27 |
28 | @InjectView(R.id.tv_call_number)
29 | TextView tv_call_number;
30 |
31 |
32 |
33 | String call_number;
34 |
35 | WindowManager.LayoutParams params;
36 | private WindowManager windowManager;
37 |
38 |
39 | @Override
40 | public IBinder onBind(Intent intent) {
41 |
42 | // Not used
43 | return null;
44 | }
45 |
46 | @Override
47 | public void onCreate() {
48 | super.onCreate();
49 |
50 |
51 | windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
52 |
53 | Display display = windowManager.getDefaultDisplay();
54 |
55 | int width = (int) (display.getWidth() * 0.9); //Display 사이즈의 90%
56 |
57 |
58 | params = new WindowManager.LayoutParams(
59 | width,
60 | WindowManager.LayoutParams.WRAP_CONTENT,
61 | WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
62 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
63 | | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
64 | | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
65 | | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
66 | PixelFormat.TRANSLUCENT);
67 |
68 |
69 | LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
70 | rootView = layoutInflater.inflate(R.layout.call_popup_top, null);
71 | ButterKnife.inject(this, rootView);
72 | setDraggable();
73 |
74 |
75 | }
76 |
77 |
78 |
79 | private void setDraggable() {
80 |
81 | rootView.setOnTouchListener(new View.OnTouchListener() {
82 | private int initialX;
83 | private int initialY;
84 | private float initialTouchX;
85 | private float initialTouchY;
86 |
87 | @Override
88 | public boolean onTouch(View v, MotionEvent event) {
89 | switch (event.getAction()) {
90 | case MotionEvent.ACTION_DOWN:
91 | initialX = params.x;
92 | initialY = params.y;
93 | initialTouchX = event.getRawX();
94 | initialTouchY = event.getRawY();
95 | return true;
96 | case MotionEvent.ACTION_UP:
97 | return true;
98 | case MotionEvent.ACTION_MOVE:
99 | params.x = initialX + (int) (event.getRawX() - initialTouchX);
100 | params.y = initialY + (int) (event.getRawY() - initialTouchY);
101 |
102 | if (rootView != null)
103 | windowManager.updateViewLayout(rootView, params);
104 | return true;
105 | }
106 | return false;
107 | }
108 | });
109 |
110 | }
111 |
112 | @Override
113 | public int onStartCommand(Intent intent, int flags, int startId) {
114 |
115 | windowManager.addView(rootView, params);
116 | setExtra(intent);
117 |
118 |
119 | if (!TextUtils.isEmpty(call_number)) {
120 | tv_call_number.setText(call_number);
121 | }
122 |
123 |
124 | return START_REDELIVER_INTENT;
125 | }
126 |
127 |
128 | private void setExtra(Intent intent) {
129 |
130 | if (intent == null) {
131 | removePopup();
132 | return;
133 | }
134 |
135 | call_number = intent.getStringExtra(EXTRA_CALL_NUMBER);
136 |
137 |
138 | }
139 |
140 |
141 | @Override
142 | public void onDestroy() {
143 | super.onDestroy();
144 | removePopup();
145 | }
146 |
147 |
148 | @OnClick(R.id.btn_close)
149 | public void removePopup() {
150 | if (rootView != null && windowManager != null) windowManager.removeView(rootView);
151 | }
152 | }
153 |
--------------------------------------------------------------------------------