Skip to content

Commit 019a577

Browse files
Added Badges
1 parent f2aa5f2 commit 019a577

File tree

11 files changed

+153
-45
lines changed

11 files changed

+153
-45
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ dependencies {
5858
implementation 'com.github.bumptech.glide:glide:4.7.1'
5959
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
6060
implementation fileTree(include: ['*.jar'], dir: 'libs')
61-
implementation 'androidx.appcompat:appcompat:1.1.0-beta01'
61+
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
6262
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
6363
testImplementation 'junit:junit:4.12'
6464
androidTestImplementation 'androidx.test:runner:1.2.0'
@@ -73,7 +73,7 @@ dependencies {
7373
implementation 'com.yqritc:recyclerview-flexibledivider:1.4.0'
7474
implementation 'com.android.volley:volley:1.1.1'
7575
implementation "ch.acra:acra-http:5.3.0"
76-
implementation 'androidx.exifinterface:exifinterface:1.1.0-alpha01'
76+
implementation 'androidx.exifinterface:exifinterface:1.1.0-beta01'
7777
implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:10.0.3'
7878
androidTestImplementation 'androidx.test:rules:1.2.0'//for adding pic to contact
7979
}

app/src/main/java/com/bald/uriah/baldphone/activities/HomeScreenActivity.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public void run() {
112112
}
113113
}
114114
};
115+
115116
private final BroadcastReceiver notificationReceiver = new BroadcastReceiver() {
116117
@Override
117118
public void onReceive(Context context, Intent intent) {
@@ -137,6 +138,7 @@ public void onReceive(Context context, Intent intent) {
137138
}
138139
};
139140

141+
140142
@Override
141143
protected void onCreate(@Nullable Bundle savedInstanceState) {
142144
super.onCreate(savedInstanceState);
@@ -286,16 +288,12 @@ protected void onResume() {
286288
}
287289

288290
LocalBroadcastManager.getInstance(this).
289-
290291
registerReceiver(notificationReceiver,
291292
new IntentFilter(NotificationListenerService.HOME_SCREEN_ACTIVITY_BROADCAST));
292293
LocalBroadcastManager.getInstance(this).
293-
294294
sendBroadcast(
295295
new Intent(ACTION_REGISTER_ACTIVITY)
296-
.
297-
298-
putExtra(KEY_EXTRA_ACTIVITY, NOTIFICATIONS_HOME_SCREEN));
296+
.putExtra(KEY_EXTRA_ACTIVITY, NOTIFICATIONS_HOME_SCREEN));
299297

300298
registerReceiver(batteryReceiver, BATTERY_FILTER);
301299
}
@@ -389,13 +387,19 @@ private boolean isActivityDefault() {
389387
}
390388

391389
public void displaySpeechRecognizer() {
392-
startActivityForResult(
393-
new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
394-
.putExtra(
395-
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
396-
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
397-
),
398-
SPEECH_REQUEST_CODE);
390+
try {
391+
startActivityForResult(
392+
new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
393+
.putExtra(
394+
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
395+
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
396+
),
397+
SPEECH_REQUEST_CODE);
398+
} catch (ActivityNotFoundException e) {
399+
Log.e(TAG, S.str(e.getMessage()));
400+
e.printStackTrace();
401+
BaldToast.error(this);
402+
}
399403
}
400404

401405
@Override

app/src/main/java/com/bald/uriah/baldphone/activities/contacts/BaseContactsActivity.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package com.bald.uriah.baldphone.activities.contacts;
2121

22+
import android.content.ActivityNotFoundException;
2223
import android.content.ContentResolver;
2324
import android.content.Context;
2425
import android.content.Intent;
@@ -27,6 +28,7 @@
2728
import android.speech.RecognizerIntent;
2829
import android.text.Editable;
2930
import android.text.TextWatcher;
31+
import android.util.Log;
3032
import android.view.KeyEvent;
3133
import android.view.View;
3234
import android.view.inputmethod.InputMethodManager;
@@ -39,6 +41,7 @@
3941
import com.bald.uriah.baldphone.R;
4042
import com.bald.uriah.baldphone.activities.BaldActivity;
4143
import com.bald.uriah.baldphone.adapters.ContactRecyclerViewAdapter;
44+
import com.bald.uriah.baldphone.utils.BaldToast;
4245
import com.bald.uriah.baldphone.utils.S;
4346
import com.bald.uriah.baldphone.utils.SoftInputAssist;
4447
import com.bald.uriah.baldphone.utils.Toggeler;
@@ -51,6 +54,7 @@
5154
* both has {@link R.layout#contacts_search} in their layout.
5255
*/
5356
abstract class BaseContactsActivity extends BaldActivity {
57+
private static final String TAG = BaseContactsActivity.class.getSimpleName();
5458
public static final int SPEECH_REQUEST_CODE = 5678;
5559
public static final String INTENT_EXTRA_CONTACT_ADAPTER_MODE = "INTENT_EXTRA_CONTACT_ADAPTER_MODE";
5660
private static final String FILTER_STATE = "FILTER_STATE";
@@ -184,13 +188,19 @@ public void afterTextChanged(Editable s) {
184188
}
185189

186190
private void displaySpeechRecognizer() {
187-
startActivityForResult(
188-
new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
189-
.putExtra(
190-
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
191-
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
192-
),
193-
SPEECH_REQUEST_CODE);
191+
try {
192+
startActivityForResult(
193+
new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
194+
.putExtra(
195+
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
196+
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
197+
),
198+
SPEECH_REQUEST_CODE);
199+
} catch (ActivityNotFoundException e) {
200+
Log.e(TAG, S.str(e.getMessage()));
201+
e.printStackTrace();
202+
BaldToast.error(this);
203+
}
194204
}
195205

196206
protected abstract Cursor getCursorForFilter(String filter, boolean favorite);

app/src/main/java/com/bald/uriah/baldphone/adapters/BaldPagerAdapter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public void obtainAppList() {
5757
numItems =
5858
numItemsBefore + (pinnedList.size() / HomeViewFactory.AMOUNT_PER_PAGE + (pinnedList.size() % HomeViewFactory.AMOUNT_PER_PAGE == 0 ? 0 : 1));
5959
notifyDataSetChanged();
60-
6160
}
6261

6362
public View getItem(int position) {

app/src/main/java/com/bald/uriah/baldphone/adapters/BaldViewAdapter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public abstract class BaldViewAdapter extends PagerAdapter {
3232
public Object instantiateItem(@NonNull ViewGroup container, int position) {
3333
View layout = getItem(position);
3434
container.addView(layout);
35+
3536
return layout;
3637
}
3738

app/src/main/java/com/bald/uriah/baldphone/services/NotificationListenerService.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
import java.lang.annotation.Retention;
3737
import java.lang.annotation.RetentionPolicy;
38+
import java.util.ArrayList;
3839
import java.util.Objects;
3940

4041
public class NotificationListenerService extends android.service.notification.NotificationListenerService {
@@ -167,15 +168,21 @@ private void sendBroadcastToNotificationsActivity() {
167168
private void sendBroadcastToHomeScreenActivity() {
168169
try {
169170
final StatusBarNotification[] statusBarNotifications = getActiveNotifications();
171+
final ArrayList<String> packages = new ArrayList<>(statusBarNotifications.length);
172+
for (final StatusBarNotification statusBarNotification : statusBarNotifications) {
173+
packages.add(statusBarNotification.getPackageName());
174+
175+
}
176+
final Intent intent = new Intent(HOME_SCREEN_ACTIVITY_BROADCAST)
177+
.putExtra("amount", statusBarNotifications.length < NOTIFICATIONS_ALOT ?
178+
statusBarNotifications.length < NOTIFICATIONS_SOME ?
179+
NOTIFICATIONS_NONE :
180+
NOTIFICATIONS_SOME :
181+
NOTIFICATIONS_ALOT)
182+
.putStringArrayListExtra("packages", packages);
183+
170184
LocalBroadcastManager.getInstance(this)
171-
.sendBroadcast(
172-
new Intent(HOME_SCREEN_ACTIVITY_BROADCAST)
173-
.putExtra("amount", statusBarNotifications.length < NOTIFICATIONS_ALOT ?
174-
statusBarNotifications.length < NOTIFICATIONS_SOME ?
175-
NOTIFICATIONS_NONE :
176-
NOTIFICATIONS_SOME :
177-
NOTIFICATIONS_ALOT)
178-
);
185+
.sendBroadcast(intent);
179186
} catch (SecurityException e) {
180187
Log.e(TAG, e.getMessage());
181188
e.printStackTrace();

app/src/main/java/com/bald/uriah/baldphone/views/FirstPageAppIcon.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import android.graphics.drawable.Drawable;
2626
import android.util.AttributeSet;
2727
import android.view.LayoutInflater;
28+
import android.view.View;
2829
import android.widget.ImageView;
2930
import android.widget.TextView;
3031
import androidx.annotation.DrawableRes;
@@ -37,6 +38,7 @@ public class FirstPageAppIcon extends BaldFrameLayoutButton {
3738
protected final LayoutInflater layoutInflater;
3839
protected ImageView imageView;
3940
protected TextView textView;
41+
protected View badge;
4042

4143
public FirstPageAppIcon(Context context) {
4244
super(context);
@@ -63,6 +65,7 @@ private void init(@Nullable AttributeSet attributeSet) {
6365
layoutInflater.inflate(R.layout.first_page_app_icon, this, true);
6466
imageView = findViewById(R.id.iv);
6567
textView = findViewById(R.id.tv);
68+
badge = findViewById(R.id.notifications_counter);
6669

6770
if (attributeSet != null) {
6871
final TypedArray styleAttributesArray = context.obtainStyledAttributes(attributeSet, R.styleable.FirstPageAppIcon);
@@ -93,12 +96,7 @@ public void setImageResource(@DrawableRes int resId) {
9396
imageView.setImageResource(resId);
9497
}
9598

96-
public ImageView getImageView() {
97-
return imageView;
99+
public void setBadgeVisibility(boolean visible) {
100+
badge.setVisibility(visible ? VISIBLE : INVISIBLE);
98101
}
99-
100-
public TextView getTextView() {
101-
return textView;
102-
}
103-
104102
}

app/src/main/java/com/bald/uriah/baldphone/views/home/HomePage1.java

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
package com.bald.uriah.baldphone.views.home;
2121

22-
import android.content.ComponentName;
23-
import android.content.Intent;
24-
import android.content.SharedPreferences;
22+
import android.content.*;
2523
import android.content.pm.ActivityInfo;
2624
import android.content.pm.PackageManager;
2725
import android.content.res.Configuration;
@@ -31,6 +29,7 @@
3129
import android.view.View;
3230
import android.view.ViewGroup;
3331
import androidx.annotation.NonNull;
32+
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
3433
import com.bald.uriah.baldphone.R;
3534
import com.bald.uriah.baldphone.activities.*;
3635
import com.bald.uriah.baldphone.activities.alarms.AlarmsActivity;
@@ -40,24 +39,44 @@
4039
import com.bald.uriah.baldphone.activities.pills.PillsActivity;
4140
import com.bald.uriah.baldphone.databases.apps.App;
4241
import com.bald.uriah.baldphone.databases.apps.AppsDatabase;
42+
import com.bald.uriah.baldphone.services.NotificationListenerService;
4343
import com.bald.uriah.baldphone.utils.BPrefs;
4444
import com.bald.uriah.baldphone.utils.BaldToast;
45+
import com.bald.uriah.baldphone.utils.D;
4546
import com.bald.uriah.baldphone.utils.S;
4647
import com.bald.uriah.baldphone.views.FirstPageAppIcon;
4748

49+
import java.util.HashSet;
50+
import java.util.Set;
51+
52+
import static com.bald.uriah.baldphone.services.NotificationListenerService.*;
53+
4854
public class HomePage1 extends HomeView {
4955
public static final String TAG = HomePage1.class.getSimpleName();
5056
private final static String WHATSAPP_PACKAGE_NAME = "com.whatsapp";
5157
private View view;
5258
private FirstPageAppIcon bt_clock, bt_camera, bt_videos, bt_assistant, bt_messages, bt_photos, bt_contacts, bt_dialer, bt_whatsapp, bt_apps, bt_reminders, bt_recent;
5359
private PackageManager packageManager;
60+
private boolean registered = false;
61+
private App app;
5462

5563
public HomePage1(@NonNull HomeScreenActivity homeScreen) {
5664
super(homeScreen);
5765
}
5866

59-
@Override
60-
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container) {
67+
private final BroadcastReceiver notificationReceiver = new BroadcastReceiver() {
68+
@Override
69+
public void onReceive(Context context, Intent intent) {
70+
final Set<String> packagesSet = new HashSet<>(intent.getStringArrayListExtra("packages"));
71+
bt_messages.setBadgeVisibility(packagesSet.contains(Telephony.Sms.getDefaultSmsPackage(homeScreen)));
72+
if (app == null) {
73+
bt_whatsapp.setBadgeVisibility(packagesSet.contains(D.WHATSAPP_PACKAGE_NAME));
74+
} else
75+
bt_whatsapp.setBadgeVisibility(packagesSet.contains(ComponentName.unflattenFromString(app.getFlattenComponentName()).getPackageName()));
76+
}
77+
};
78+
79+
@Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container) {
6180
view = inflater.inflate(R.layout.fragment_home_page1, container, false);
6281
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
6382
view.findViewById(R.id.clock).setVisibility(View.GONE);
@@ -68,6 +87,28 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container)
6887
return view;
6988
}
7089

90+
@Override protected void onAttachedToWindow() {
91+
super.onAttachedToWindow();
92+
if (!registered) {
93+
LocalBroadcastManager.getInstance(homeScreen)
94+
.registerReceiver(notificationReceiver,
95+
new IntentFilter(NotificationListenerService.HOME_SCREEN_ACTIVITY_BROADCAST));
96+
registered = true;
97+
LocalBroadcastManager.getInstance(homeScreen).sendBroadcast(
98+
new Intent(ACTION_REGISTER_ACTIVITY)
99+
.putExtra(KEY_EXTRA_ACTIVITY, NOTIFICATIONS_HOME_SCREEN));
100+
}
101+
}
102+
103+
@Override protected void onDetachedFromWindow() {
104+
super.onDetachedFromWindow();
105+
if (registered) {
106+
LocalBroadcastManager.getInstance(homeScreen)
107+
.unregisterReceiver(notificationReceiver);
108+
registered = false;
109+
}
110+
}
111+
71112
private void attachXml() {
72113
bt_apps = view.findViewById(R.id.bt_apps);
73114
bt_contacts = view.findViewById(R.id.bt_contacts);
@@ -99,14 +140,13 @@ private Intent getCameraIntent() {
99140

100141
private void genOnClickListeners() {
101142
final SharedPreferences sharedPreferences = BPrefs.get(homeScreen);
102-
final App app;
103143
if (sharedPreferences.contains(BPrefs.CUSTOM_APP_KEY)) {
104144
app = AppsDatabase.getInstance(homeScreen).appsDatabaseDao().findByFlattenComponentName(sharedPreferences.getString(BPrefs.CUSTOM_APP_KEY, null));
105145
if (app == null)
106146
sharedPreferences.edit().remove(BPrefs.CUSTOM_APP_KEY).apply();
107-
} else {
147+
} else
108148
app = null;
109-
}
149+
110150
if (app == null) {
111151
if (S.isPackageInstalled(homeScreen, WHATSAPP_PACKAGE_NAME))
112152
bt_whatsapp.setOnClickListener(v -> homeScreen.startActivity(
@@ -152,4 +192,5 @@ private void genOnClickListeners() {
152192
});
153193
bt_assistant.setOnClickListener(v -> homeScreen.startActivity(new Intent(homeScreen, AssistantActivity.class)));
154194
}
195+
155196
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
22+
android:shape="rectangle">
23+
<corners android:radius="?bald_button_pill_corners_radius"/>
24+
<solid android:color="@color/red"/>
25+
<stroke
26+
android:width="?bald_stroke_size"
27+
android:color="?bald_stroke_color"/>
28+
</shape>

0 commit comments

Comments
 (0)