├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── drawable-hdpi │ │ │ │ ├── ic_edit.png │ │ │ │ ├── ic_delete.png │ │ │ │ └── ic_action_settings.png │ │ │ ├── drawable-mdpi │ │ │ │ ├── ic_edit.png │ │ │ │ ├── ic_delete.png │ │ │ │ └── ic_action_settings.png │ │ │ ├── drawable-xhdpi │ │ │ │ ├── ic_delete.png │ │ │ │ ├── ic_edit.png │ │ │ │ └── ic_action_settings.png │ │ │ ├── drawable-xxhdpi │ │ │ │ ├── ic_edit.png │ │ │ │ ├── ic_delete.png │ │ │ │ └── ic_action_settings.png │ │ │ ├── drawable-xxxhdpi │ │ │ │ ├── ic_edit.png │ │ │ │ ├── ic_delete.png │ │ │ │ └── ic_action_settings.png │ │ │ ├── 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 │ │ │ │ └── divider.xml │ │ │ ├── layout │ │ │ │ ├── recycler_item_space.xml │ │ │ │ ├── activity_main.xml │ │ │ │ ├── reccyler_item_notice.xml │ │ │ │ ├── layout_recycler.xml │ │ │ │ ├── activity_edit.xml │ │ │ │ ├── recycler_item_label.xml │ │ │ │ ├── layout_item.xml │ │ │ │ ├── layout_button_bar.xml │ │ │ │ ├── recycler_item_filter.xml │ │ │ │ ├── layout_permission.xml │ │ │ │ └── layout_edit.xml │ │ │ ├── menu │ │ │ │ ├── menu_dara.xml │ │ │ │ └── menu_sheet.xml │ │ │ ├── values │ │ │ │ ├── styles.xml │ │ │ │ ├── colors.xml │ │ │ │ └── strings.xml │ │ │ └── values-zh │ │ │ │ └── strings.xml │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── mthli │ │ │ │ └── dara │ │ │ │ ├── event │ │ │ │ ├── UpdateRecordEvent.java │ │ │ │ ├── RequestNotificationListEvent.java │ │ │ │ ├── ClickFilterEvent.java │ │ │ │ ├── ClickNoticeEvent.java │ │ │ │ ├── NotificationRemovedEvent.java │ │ │ │ └── ResponseNotificationListEvent.java │ │ │ │ ├── widget │ │ │ │ ├── item │ │ │ │ │ ├── Label.java │ │ │ │ │ ├── Space.java │ │ │ │ │ ├── Notice.java │ │ │ │ │ └── Filter.java │ │ │ │ ├── holder │ │ │ │ │ ├── LabelHolder.java │ │ │ │ │ ├── SpaceHolder.java │ │ │ │ │ ├── NoticeHolder.java │ │ │ │ │ └── FilterHolder.java │ │ │ │ ├── CustomViewTransformer.java │ │ │ │ ├── CustomRecyclerView.java │ │ │ │ ├── DaraItemDecoration.java │ │ │ │ ├── ButtonBarLayout.java │ │ │ │ ├── PermissionLayout.java │ │ │ │ ├── adapter │ │ │ │ │ └── DaraAdapter.java │ │ │ │ ├── EditLayout.java │ │ │ │ ├── CustomMenuSheetView.java │ │ │ │ └── RecyclerLayout.java │ │ │ │ ├── record │ │ │ │ └── Record.java │ │ │ │ ├── app │ │ │ │ ├── DaraApplication.java │ │ │ │ ├── MainActivity.java │ │ │ │ ├── DaraService.java │ │ │ │ └── EditActivity.java │ │ │ │ └── util │ │ │ │ ├── KeyboardUtils.java │ │ │ │ ├── RxBus.java │ │ │ │ ├── DisplayUtils.java │ │ │ │ ├── AppInfoUtils.java │ │ │ │ └── RegExUtils.java │ │ └── AndroidManifest.xml │ └── androidTest │ │ └── java │ │ └── io │ │ └── github │ │ └── mthli │ │ └── dara │ │ └── ApplicationTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── README.md ├── gradlew.bat ├── gradlew └── LICENSE /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/drawable-hdpi/ic_edit.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/drawable-mdpi/ic_edit.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/drawable-hdpi/ic_delete.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/drawable-mdpi/ic_delete.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/drawable-xhdpi/ic_delete.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/drawable-xhdpi/ic_edit.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/drawable-xxhdpi/ic_edit.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/drawable-xxxhdpi/ic_edit.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/drawable-xxhdpi/ic_delete.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/drawable-xxxhdpi/ic_delete.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/event/UpdateRecordEvent.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.event; 2 | 3 | public class UpdateRecordEvent {} 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/drawable-hdpi/ic_action_settings.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/drawable-mdpi/ic_action_settings.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/drawable-xhdpi/ic_action_settings.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_action_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/drawable-xxhdpi/ic_action_settings.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_action_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mthli/Dara/master/app/src/main/res/drawable-xxxhdpi/ic_action_settings.png -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/event/RequestNotificationListEvent.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.event; 2 | 3 | public class RequestNotificationListEvent {} 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/divider.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/item/Label.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget.item; 2 | 3 | public class Label { 4 | private String mText; 5 | 6 | public Label(String text) { 7 | mText = text; 8 | } 9 | 10 | public String getText() { 11 | return mText; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/item/Space.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget.item; 2 | 3 | public class Space { 4 | private int mHeight; 5 | 6 | public Space(int height) { 7 | mHeight = height; 8 | } 9 | 10 | public int getHeight() { 11 | return mHeight; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/record/Record.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.record; 2 | 3 | import com.orm.SugarRecord; 4 | 5 | public class Record extends SugarRecord { 6 | public String packageName; 7 | public Boolean isRegEx; 8 | public String title; 9 | public String content; 10 | 11 | public Record() {} 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/recycler_item_space.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/event/ClickFilterEvent.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.event; 2 | 3 | import io.github.mthli.dara.widget.item.Filter; 4 | 5 | public class ClickFilterEvent { 6 | private Filter mFilter; 7 | 8 | public ClickFilterEvent(Filter filter) { 9 | mFilter = filter; 10 | } 11 | 12 | public Filter getFilter() { 13 | return mFilter; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/event/ClickNoticeEvent.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.event; 2 | 3 | import io.github.mthli.dara.widget.item.Notice; 4 | 5 | public class ClickNoticeEvent { 6 | private Notice mNotice; 7 | 8 | public ClickNoticeEvent(Notice notice) { 9 | mNotice = notice; 10 | } 11 | 12 | public Notice getNotice() { 13 | return mNotice; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_dara.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/androidTest/java/io/github/mthli/dara/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | 11 | public ApplicationTest() { 12 | super(Application.class); 13 | } 14 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/item/Notice.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget.item; 2 | 3 | import android.service.notification.StatusBarNotification; 4 | 5 | public class Notice { 6 | private StatusBarNotification mNotification; 7 | 8 | public Notice(StatusBarNotification notification) { 9 | mNotification = notification; 10 | } 11 | 12 | public StatusBarNotification getNotification() { 13 | return mNotification; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/app/DaraApplication.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.app; 2 | 3 | import android.app.Application; 4 | 5 | import com.orm.SugarContext; 6 | 7 | public class DaraApplication extends Application { 8 | @Override 9 | public void onCreate() { 10 | super.onCreate(); 11 | SugarContext.init(this); 12 | } 13 | 14 | @Override 15 | public void onTerminate() { 16 | super.onTerminate(); 17 | SugarContext.terminate(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/res/layout/reccyler_item_notice.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/event/NotificationRemovedEvent.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.event; 2 | 3 | import android.service.notification.StatusBarNotification; 4 | 5 | public class NotificationRemovedEvent { 6 | private StatusBarNotification mStatusBarNotification; 7 | 8 | public NotificationRemovedEvent(StatusBarNotification statusBarNotification) { 9 | mStatusBarNotification = statusBarNotification; 10 | } 11 | 12 | public StatusBarNotification getStatusBarNotification() { 13 | return mStatusBarNotification; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Log Files 26 | *.log 27 | 28 | # Android Studio Navigation editor temp files 29 | .navigation/ 30 | 31 | # Android Studio captures folder 32 | captures/ 33 | 34 | # Others 35 | .idea/ 36 | *.directory 37 | *.iml 38 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_sheet.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 10 | 11 | 12 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/event/ResponseNotificationListEvent.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.event; 2 | 3 | import android.service.notification.StatusBarNotification; 4 | 5 | import java.util.List; 6 | 7 | public class ResponseNotificationListEvent { 8 | private List mStatusBarNotificationList; 9 | 10 | public ResponseNotificationListEvent(List statusBarNotificationList) { 11 | mStatusBarNotificationList = statusBarNotificationList; 12 | } 13 | 14 | public List getStatusBarNotificationList() { 15 | return mStatusBarNotificationList; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_recycler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/holder/LabelHolder.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget.holder; 2 | 3 | import android.support.v7.widget.AppCompatTextView; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.View; 6 | 7 | import io.github.mthli.dara.R; 8 | import io.github.mthli.dara.widget.item.Label; 9 | 10 | public class LabelHolder extends RecyclerView.ViewHolder { 11 | private AppCompatTextView mLabelView; 12 | 13 | public LabelHolder(View view) { 14 | super(view); 15 | mLabelView = (AppCompatTextView) view.findViewById(R.id.label); 16 | } 17 | 18 | public void setLabel(Label label) { 19 | mLabelView.setText(label.getText()); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /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 /home/matthew/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_edit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 13 | 14 | 15 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/holder/SpaceHolder.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget.holder; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.View; 5 | import android.widget.FrameLayout; 6 | 7 | import io.github.mthli.dara.R; 8 | import io.github.mthli.dara.widget.item.Space; 9 | 10 | public class SpaceHolder extends RecyclerView.ViewHolder { 11 | private FrameLayout mFrameLayout; 12 | 13 | public SpaceHolder(View view) { 14 | super(view); 15 | mFrameLayout = (FrameLayout) view.findViewById(R.id.space); 16 | } 17 | 18 | public void setSpace(Space space) { 19 | mFrameLayout.getLayoutParams().height = space.getHeight(); 20 | mFrameLayout.requestLayout(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/item/Filter.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget.item; 2 | 3 | import io.github.mthli.dara.record.Record; 4 | 5 | public class Filter { 6 | private int mColor; 7 | private Record mRecord; 8 | 9 | public Filter() { 10 | mColor = 0; 11 | mRecord = null; 12 | } 13 | 14 | public Filter(int color, Record record) { 15 | mColor = color; 16 | mRecord = record; 17 | } 18 | 19 | public int getColor() { 20 | return mColor; 21 | } 22 | 23 | public void setColor(int color) { 24 | mColor = color; 25 | } 26 | 27 | public Record getRecord() { 28 | return mRecord; 29 | } 30 | 31 | public void setRecord(Record record) { 32 | mRecord = record; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/util/KeyboardUtils.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.util; 2 | 3 | import android.content.Context; 4 | import android.view.View; 5 | import android.view.inputmethod.InputMethodManager; 6 | 7 | public class KeyboardUtils { 8 | public static void showKeyboard(Context context, View view) { 9 | InputMethodManager manager = (InputMethodManager) context 10 | .getSystemService(Context.INPUT_METHOD_SERVICE); 11 | manager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT); 12 | } 13 | 14 | public static void hideKeyboard(Context context, View view) { 15 | InputMethodManager manager = (InputMethodManager) context 16 | .getSystemService(Context.INPUT_METHOD_SERVICE); 17 | manager.hideSoftInputFromWindow(view.getWindowToken(), 0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/CustomViewTransformer.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget; 2 | 3 | import android.view.View; 4 | 5 | import com.flipboard.bottomsheet.BottomSheetLayout; 6 | import com.flipboard.bottomsheet.ViewTransformer; 7 | 8 | public class CustomViewTransformer implements ViewTransformer { 9 | @Override 10 | public void transformView(float translation, float maxTranslation, 11 | float peekedTranslation, BottomSheetLayout parent, View view) { 12 | // DO NOTHING 13 | } 14 | 15 | @Override 16 | public float getDimAlpha(float translation, float maxTranslation, 17 | float peekedTranslation, BottomSheetLayout parent, View view) { 18 | float progress = translation / maxTranslation; 19 | return progress * 0.54f; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/util/RxBus.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.util; 2 | 3 | import rx.Observable; 4 | import rx.subjects.PublishSubject; 5 | import rx.subjects.SerializedSubject; 6 | import rx.subjects.Subject; 7 | 8 | public class RxBus { 9 | private static final RxBus sRxBus = new RxBus(); 10 | 11 | public static RxBus getInstance() { 12 | return sRxBus; 13 | } 14 | 15 | private Subject mSubject = new SerializedSubject<>(PublishSubject.create()); 16 | 17 | private RxBus() {} 18 | 19 | public void post(Object object) { 20 | mSubject.onNext(object); 21 | } 22 | 23 | public Observable toObservable(Class eventType) { 24 | return mSubject.ofType(eventType); 25 | } 26 | 27 | public boolean hasObservers() { 28 | return mSubject.hasObservers(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /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 "io.github.mthli.dara" 9 | minSdkVersion 21 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | compile fileTree(include: ['*.jar'], dir: 'libs') 25 | compile 'com.android.support:appcompat-v7:23.4.0' 26 | compile 'com.android.support:customtabs:23.4.0' 27 | compile 'com.android.support:recyclerview-v7:23.4.0' 28 | compile 'com.flipboard:bottomsheet-commons:1.5.1' 29 | compile 'com.github.satyan:sugar:1.5' 30 | compile 'io.reactivex:rxandroid:1.2.0' 31 | } 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Dara 2 | === 3 | 4 | Shielding notifications that you don't want to see. 5 | 6 | Support Android Lollipop and up. 7 | 8 | [**STOP DEVELOPMENT**](https://code.google.com/p/android/issues/detail?id=93242 "NotificationListenerService - new method beforeNoitifcationPosted(StatusBarNotification sbn)"). 9 | 10 | ## License 11 | 12 | Copyright (C) 2016 Matthew Lee 13 | 14 | Licensed under the Apache License, Version 2.0 (the "License"); 15 | you may not use this file except in compliance with the License. 16 | You may obtain a copy of the License at 17 | 18 | http://www.apache.org/licenses/LICENSE-2.0 19 | 20 | Unless required by applicable law or agreed to in writing, software 21 | distributed under the License is distributed on an "AS IS" BASIS, 22 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 23 | See the License for the specific language governing permissions and 24 | limitations under the License. 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/recycler_item_label.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 15 | 16 | 17 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 16 | 17 | 21 | 22 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/holder/NoticeHolder.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget.holder; 2 | 3 | import android.support.v7.widget.RecyclerView; 4 | import android.view.View; 5 | import android.widget.FrameLayout; 6 | 7 | import io.github.mthli.dara.event.ClickNoticeEvent; 8 | import io.github.mthli.dara.util.RxBus; 9 | import io.github.mthli.dara.widget.item.Notice; 10 | 11 | public class NoticeHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 12 | private FrameLayout mFrameNotice; 13 | private Notice mNotice; 14 | 15 | public NoticeHolder(View view) { 16 | super(view); 17 | mFrameNotice = (FrameLayout) view; 18 | mFrameNotice.setOnClickListener(this); 19 | } 20 | 21 | @Override 22 | public void onClick(View view) { 23 | if (mNotice != null) { 24 | RxBus.getInstance().post(new ClickNoticeEvent(mNotice)); 25 | } 26 | } 27 | 28 | public void setNotice(Notice notice) { 29 | mNotice = notice; 30 | 31 | mFrameNotice.removeAllViews(); 32 | View view = notice.getNotification().getNotification().contentView 33 | .apply(mFrameNotice.getContext().getApplicationContext(), mFrameNotice); 34 | mFrameNotice.addView(view); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/CustomRecyclerView.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.Configuration; 5 | import android.support.annotation.Nullable; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.util.AttributeSet; 8 | import android.view.View; 9 | 10 | import io.github.mthli.dara.util.DisplayUtils; 11 | 12 | public class CustomRecyclerView extends RecyclerView { 13 | public CustomRecyclerView(Context context) { 14 | super(context); 15 | } 16 | 17 | public CustomRecyclerView(Context context, @Nullable AttributeSet attrs) { 18 | super(context, attrs); 19 | } 20 | 21 | public CustomRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 22 | super(context, attrs, defStyleAttr); 23 | } 24 | 25 | @Override 26 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 27 | if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { 28 | int width = View.MeasureSpec.getSize(widthMeasureSpec); 29 | int dp480 = (int) DisplayUtils.dp2px(getContext(), 480.0f); 30 | width = width < dp480 ? width : dp480; 31 | widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); 32 | } 33 | 34 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/util/DisplayUtils.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.util; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Context; 5 | import android.graphics.Outline; 6 | import android.os.Build; 7 | import android.view.View; 8 | import android.view.ViewOutlineProvider; 9 | 10 | public class DisplayUtils { 11 | @TargetApi(Build.VERSION_CODES.LOLLIPOP) 12 | public static class ShadowOutline extends ViewOutlineProvider { 13 | private int width; 14 | private int height; 15 | 16 | public ShadowOutline(int width, int height) { 17 | this.width = width; 18 | this.height = height; 19 | } 20 | 21 | @Override 22 | public void getOutline(View view, Outline outline) { 23 | outline.setRect(0, 0, width, height); 24 | } 25 | } 26 | 27 | public static float dp2px(Context context, float dp) { 28 | return context.getResources().getDisplayMetrics().density * dp; 29 | } 30 | 31 | public static float getDensity(Context context) { 32 | return context.getResources().getDisplayMetrics().density; 33 | } 34 | 35 | public static int getStatusBarHeight(Context context) { 36 | int result = 0; 37 | int resourceId = context.getResources() 38 | .getIdentifier("status_bar_height", "dimen", "android"); 39 | if (resourceId > 0) { 40 | result = context.getResources().getDimensionPixelSize(resourceId); 41 | } 42 | return result; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #FF004D40 6 | #FF00695C 7 | #FF00796B 8 | #FF00897B 9 | #FF009688 10 | #FF26A69A 11 | #FF4DB6AC 12 | #FF80CBC4 13 | #FFB2DFDB 14 | 15 | #FF263238 16 | #FF37474F 17 | #FF455A64 18 | #FF546E7A 19 | #FF607D8B 20 | #FF78909C 21 | #FF90A4AE 22 | #FFB0BEC5 23 | #FFCFD8DC 24 | 25 | #FFD32F2F 26 | #FFF44336 27 | #FFE57373 28 | 29 | #DE000000 30 | #8A000000 31 | #61000000 32 | #33000000 33 | 34 | @android:color/black 35 | #26000000 36 | @android:color/white 37 | @android:color/transparent 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/DaraItemDecoration.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget; 2 | 3 | import android.content.Context; 4 | import android.graphics.Canvas; 5 | import android.graphics.drawable.Drawable; 6 | import android.support.v4.content.ContextCompat; 7 | import android.support.v7.widget.RecyclerView; 8 | import android.view.View; 9 | 10 | import io.github.mthli.dara.R; 11 | import io.github.mthli.dara.util.DisplayUtils; 12 | 13 | public class DaraItemDecoration extends RecyclerView.ItemDecoration { 14 | private Drawable mDivider; 15 | 16 | public DaraItemDecoration(Context context) { 17 | mDivider = ContextCompat.getDrawable(context, R.drawable.divider); 18 | } 19 | 20 | @Override 21 | public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { 22 | int count = parent.getChildCount(); 23 | for (int i = 0; i < count; i++) { 24 | View child = parent.getChildAt(i); 25 | if (child.getId() == R.id.frame_label || i + 1 >= count) { 26 | continue; 27 | } 28 | 29 | RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); 30 | int top = child.getBottom() + params.bottomMargin; 31 | int right = parent.getWidth() - parent.getPaddingRight(); 32 | int bottom = top + mDivider.getIntrinsicHeight(); 33 | 34 | int left = parent.getPaddingLeft(); 35 | if (child.getId() == R.id.frame_filter) { 36 | left += (int) DisplayUtils.dp2px(parent.getContext(), 4.0f); 37 | } else { 38 | left += (int) DisplayUtils.dp2px(parent.getContext(), 64.0f); 39 | } 40 | 41 | mDivider.setBounds(left, top, right, bottom); 42 | mDivider.draw(c); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/util/AppInfoUtils.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.util; 2 | 3 | import android.content.Context; 4 | import android.content.pm.ApplicationInfo; 5 | import android.content.pm.PackageManager; 6 | import android.graphics.drawable.Drawable; 7 | 8 | public class AppInfoUtils { 9 | public static Drawable getAppIcon(Context context, String packageName) { 10 | try { 11 | return context.getPackageManager().getApplicationIcon(packageName); 12 | } catch (PackageManager.NameNotFoundException e) { 13 | e.printStackTrace(); 14 | return null; 15 | } 16 | } 17 | 18 | public static ApplicationInfo getAppInfo(Context context, String packageName) { 19 | try { 20 | return context.getPackageManager().getApplicationInfo(packageName, 0); 21 | } catch (PackageManager.NameNotFoundException e) { 22 | e.printStackTrace(); 23 | return null; 24 | } 25 | } 26 | 27 | public static String getAppLabel(Context context, String packageName) { 28 | try { 29 | ApplicationInfo info = context.getPackageManager() 30 | .getApplicationInfo(packageName, 0); 31 | return context.getPackageManager().getApplicationLabel(info).toString(); 32 | } catch (PackageManager.NameNotFoundException e) { 33 | e.printStackTrace(); 34 | return null; 35 | } 36 | } 37 | 38 | public static boolean isSystemApp(Context context, String packageName) { 39 | try { 40 | ApplicationInfo info = context.getPackageManager().getApplicationInfo(packageName, 0); 41 | return (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0; 42 | } catch (PackageManager.NameNotFoundException e) { 43 | e.printStackTrace(); 44 | return false; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_button_bar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 18 | 19 | 20 | 30 | 31 | 32 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 6 | 7 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /app/src/main/res/values-zh/strings.xml: -------------------------------------------------------------------------------- 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 | 54 | 请输入满足要求的标题规则 55 | 56 | 57 | 内容规则过长 58 | 59 | 60 | 请输入满足要求的内容规则 61 | 62 | 63 | 请输入满足要求的标题或内容规则 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dara 5 | 6 | 7 | Confirm 8 | Cancel 9 | Detail 10 | 11 | 12 | 13 | TITLE    14 | 15 | 16 | CONTENT  17 | 18 | - 19 | 20 | 21 | #Title #keywords 22 | Title 23 | #Content #keywords 24 | Content 25 | 26 | 27 | Notification center 28 | 29 | 30 | Edit 31 | Delete 32 | Open app notification 33 | 34 | 35 | 36 | Grant permission to shield notifications that you don\'t want to see. 37 | 38 | Access 39 | Cancel 40 | Detail 41 | 42 | 43 | System app 44 | User app 45 | 46 | 47 | RegEx 48 | 49 | 50 | Action successful 51 | Action failed 52 | 53 | Title rule too long 54 | 55 | 56 | Please input meet title rule 57 | 58 | 59 | Content rule too long 60 | 61 | 62 | Please input meet content rule 63 | 64 | 65 | Please input meet title or content rule 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /app/src/main/res/layout/recycler_item_filter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | 14 | 15 | 16 | 19 | 20 | 33 | 34 | 35 | 40 | 41 | 42 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/ButtonBarLayout.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.Nullable; 5 | import android.support.v7.widget.AppCompatButton; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.widget.RelativeLayout; 9 | 10 | import io.github.mthli.dara.R; 11 | 12 | public class ButtonBarLayout extends RelativeLayout implements View.OnClickListener { 13 | public interface ButtonBarLayoutListener { 14 | void onPositiveButtonClick(); 15 | void onNegativeButtonClick(); 16 | void onNeutralButtonClick(); 17 | } 18 | 19 | private ButtonBarLayoutListener mButtonBarLayoutListener; 20 | 21 | private AppCompatButton mPositiveButton; 22 | private AppCompatButton mNegativeButton; 23 | private AppCompatButton mNeutralButton; 24 | 25 | public ButtonBarLayout(Context context) { 26 | super(context); 27 | } 28 | 29 | public ButtonBarLayout(Context context, @Nullable AttributeSet attrs) { 30 | super(context, attrs); 31 | } 32 | 33 | public ButtonBarLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 34 | super(context, attrs, defStyleAttr); 35 | } 36 | 37 | public void setButtonBarLayoutListener(ButtonBarLayoutListener buttonBarLayoutListener) { 38 | mButtonBarLayoutListener = buttonBarLayoutListener; 39 | } 40 | 41 | @Override 42 | protected void onFinishInflate() { 43 | super.onFinishInflate(); 44 | 45 | mPositiveButton = (AppCompatButton) findViewById(R.id.positive); 46 | mNegativeButton = (AppCompatButton) findViewById(R.id.negative); 47 | mNeutralButton = (AppCompatButton) findViewById(R.id.neutral); 48 | 49 | mPositiveButton.setOnClickListener(this); 50 | mNegativeButton.setOnClickListener(this); 51 | mNeutralButton.setOnClickListener(this); 52 | } 53 | 54 | @Override 55 | public void onClick(View view) { 56 | if (view == mPositiveButton) { 57 | if (mButtonBarLayoutListener != null) { 58 | mButtonBarLayoutListener.onPositiveButtonClick(); 59 | } 60 | } else if (view == mNegativeButton) { 61 | if (mButtonBarLayoutListener != null) { 62 | mButtonBarLayoutListener.onNegativeButtonClick(); 63 | } 64 | } else if (view == mNeutralButton) { 65 | if (mButtonBarLayoutListener != null) { 66 | mButtonBarLayoutListener.onNeutralButtonClick(); 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_permission.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 19 | 20 | 21 | 27 | 28 | 35 | 36 | 37 | 44 | 45 | 46 | 47 | 48 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/PermissionLayout.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget; 2 | 3 | import android.content.Context; 4 | import android.content.res.Configuration; 5 | import android.support.annotation.Nullable; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | import android.widget.FrameLayout; 9 | 10 | import io.github.mthli.dara.R; 11 | import io.github.mthli.dara.util.DisplayUtils; 12 | 13 | public class PermissionLayout extends FrameLayout implements View.OnClickListener { 14 | public interface PermissionLayoutListener { 15 | void onPositionClick(); 16 | void onNegativeClick(); 17 | void onNeutralClick(); 18 | } 19 | 20 | private PermissionLayoutListener mPermissionLayoutListener; 21 | 22 | public PermissionLayout(Context context) { 23 | super(context); 24 | } 25 | 26 | public PermissionLayout(Context context, @Nullable AttributeSet attrs) { 27 | super(context, attrs); 28 | } 29 | 30 | public PermissionLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 31 | super(context, attrs, defStyleAttr); 32 | } 33 | 34 | public void setPermissionLayoutListener(PermissionLayoutListener permissionLayoutListener) { 35 | mPermissionLayoutListener = permissionLayoutListener; 36 | } 37 | 38 | @Override 39 | protected void onFinishInflate() { 40 | super.onFinishInflate(); 41 | findViewById(R.id.positive).setOnClickListener(this); 42 | findViewById(R.id.negative).setOnClickListener(this); 43 | findViewById(R.id.neutral).setOnClickListener(this); 44 | } 45 | 46 | @Override 47 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 48 | if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { 49 | int width = View.MeasureSpec.getSize(widthMeasureSpec); 50 | int dp480 = (int) DisplayUtils.dp2px(getContext(), 480.0f); 51 | width = width < dp480 ? width : dp480; 52 | widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); 53 | } 54 | 55 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 56 | } 57 | 58 | @Override 59 | public void onClick(View view) { 60 | if (view.getId() == R.id.positive) { 61 | if (mPermissionLayoutListener != null) { 62 | mPermissionLayoutListener.onPositionClick(); 63 | } 64 | } else if (view.getId() == R.id.negative) { 65 | if (mPermissionLayoutListener != null) { 66 | mPermissionLayoutListener.onNegativeClick(); 67 | } 68 | } else if (view.getId() == R.id.neutral) { 69 | if (mPermissionLayoutListener != null) { 70 | mPermissionLayoutListener.onNeutralClick(); 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/holder/FilterHolder.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget.holder; 2 | 3 | import android.content.Context; 4 | import android.support.v4.content.ContextCompat; 5 | import android.support.v7.widget.AppCompatTextView; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.text.SpannableStringBuilder; 8 | import android.text.Spanned; 9 | import android.text.TextUtils; 10 | import android.text.style.ForegroundColorSpan; 11 | import android.view.View; 12 | 13 | import io.github.mthli.dara.R; 14 | import io.github.mthli.dara.event.ClickFilterEvent; 15 | import io.github.mthli.dara.util.RxBus; 16 | import io.github.mthli.dara.widget.item.Filter; 17 | 18 | public class FilterHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 19 | private Context mContext; 20 | private View mColorView; 21 | private AppCompatTextView mTitleView; 22 | private AppCompatTextView mContentView; 23 | private Filter mFilter; 24 | 25 | public FilterHolder(View view) { 26 | super(view); 27 | view.setOnClickListener(this); 28 | mContext = view.getContext(); 29 | mColorView = view.findViewById(R.id.color); 30 | mTitleView = (AppCompatTextView) view.findViewById(R.id.title); 31 | mContentView = (AppCompatTextView) view.findViewById(R.id.content); 32 | } 33 | 34 | @Override 35 | public void onClick(View view) { 36 | if (mFilter != null) { 37 | RxBus.getInstance().post(new ClickFilterEvent(mFilter)); 38 | } 39 | } 40 | 41 | public void setFilter(Filter filter) { 42 | mFilter = filter; 43 | mColorView.setBackgroundColor(filter.getColor()); 44 | 45 | ForegroundColorSpan primary = new ForegroundColorSpan(ContextCompat 46 | .getColor(mContext, R.color.text_primary)); 47 | ForegroundColorSpan secondary = new ForegroundColorSpan(ContextCompat 48 | .getColor(mContext, R.color.text_secondary)); 49 | String empty = mContext.getString(R.string.filter_empty); 50 | 51 | SpannableStringBuilder builder = new SpannableStringBuilder(); 52 | String title = mContext.getString(R.string.filter_title); 53 | int next = title.length(); 54 | if (TextUtils.isEmpty(filter.getRecord().title)) { 55 | title += empty; 56 | } else { 57 | title += filter.getRecord().title; 58 | } 59 | builder.append(title); 60 | builder.setSpan(primary, 0, next, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 61 | builder.setSpan(secondary, next, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 62 | mTitleView.setText(builder); 63 | 64 | builder = new SpannableStringBuilder(); 65 | String content = mContext.getString(R.string.filter_content); 66 | next = content.length(); 67 | if (TextUtils.isEmpty(filter.getRecord().content)) { 68 | content += empty; 69 | } else { 70 | content += filter.getRecord().content; 71 | } 72 | builder.append(content); 73 | builder.setSpan(primary, 0, next, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 74 | builder.setSpan(secondary, next, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); 75 | mContentView.setText(builder); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/util/RegExUtils.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.util; 2 | 3 | import android.text.TextUtils; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import java.util.regex.Matcher; 8 | import java.util.regex.Pattern; 9 | import java.util.regex.PatternSyntaxException; 10 | 11 | public class RegExUtils { 12 | private static final String HASHTAG_LETTERS = "\\p{L}\\p{M}"; 13 | private static final String HASHTAG_NUMERALS = "\\p{Nd}"; 14 | private static final String HASHTAG_SPECIAL_CHARS = "_" + //underscore 15 | "\\u200c" + // ZERO WIDTH NON-JOINER (ZWNJ) 16 | "\\u200d" + // ZERO WIDTH JOINER (ZWJ) 17 | "\\ua67e" + // CYRILLIC KAVYKA 18 | "\\u05be" + // HEBREW PUNCTUATION MAQAF 19 | "\\u05f3" + // HEBREW PUNCTUATION GERESH 20 | "\\u05f4" + // HEBREW PUNCTUATION GERSHAYIM 21 | "\\uff5e" + // FULLWIDTH TILDE 22 | "\\u301c" + // WAVE DASH 23 | "\\u309b" + // KATAKANA-HIRAGANA VOICED SOUND MARK 24 | "\\u309c" + // KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK 25 | "\\u30a0" + // KATAKANA-HIRAGANA DOUBLE HYPHEN 26 | "\\u30fb" + // KATAKANA MIDDLE DOT 27 | "\\u3003" + // DITTO MARK 28 | "\\u0f0b" + // TIBETAN MARK INTERSYLLABIC TSHEG 29 | "\\u0f0c" + // TIBETAN MARK DELIMITER TSHEG BSTAR 30 | "\\u00b7"; // MIDDLE DOT 31 | 32 | private static final String HASHTAG_LETTERS_NUMERALS = HASHTAG_LETTERS 33 | + HASHTAG_NUMERALS 34 | + HASHTAG_SPECIAL_CHARS; 35 | private static final String HASHTAG_LETTERS_SET = "[" 36 | + HASHTAG_LETTERS 37 | + "]"; 38 | private static final String HASHTAG_LETTERS_NUMERALS_SET = "[" 39 | + HASHTAG_LETTERS_NUMERALS 40 | + "]"; 41 | 42 | private static Pattern sValidPattern; 43 | private static Pattern sInvalidPattern; 44 | 45 | public static List getHashTags(String text) { 46 | List list = new ArrayList<>(); 47 | if (TextUtils.isEmpty(text)) { 48 | return list; 49 | } 50 | 51 | if (sValidPattern == null) { 52 | sValidPattern = Pattern.compile("(^|[^&" 53 | + HASHTAG_LETTERS_NUMERALS 54 | + "])(#|\uFF03)(?!\uFE0F|\u20E3)(" 55 | + HASHTAG_LETTERS_NUMERALS_SET 56 | + "*" 57 | + HASHTAG_LETTERS_SET 58 | + HASHTAG_LETTERS_NUMERALS_SET 59 | + "*)", Pattern.CASE_INSENSITIVE); 60 | } 61 | if (sInvalidPattern == null) { 62 | sInvalidPattern = Pattern.compile("^(?:[##]|://)"); 63 | } 64 | 65 | Matcher matcher = sValidPattern.matcher(text); 66 | while (matcher.find()) { 67 | String after = text.substring(matcher.end()); 68 | if (!sInvalidPattern.matcher(after).find()) { 69 | list.add(matcher.group()); 70 | } 71 | } 72 | 73 | return list; 74 | } 75 | 76 | public static boolean isRegEx(String text) { 77 | if (TextUtils.isEmpty(text)) { 78 | return false; 79 | } 80 | 81 | try { 82 | Pattern.compile(text); 83 | return true; 84 | } catch (PatternSyntaxException e) { 85 | e.printStackTrace(); 86 | return false; 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/adapter/DaraAdapter.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.ViewGroup; 7 | 8 | import java.util.List; 9 | 10 | import io.github.mthli.dara.R; 11 | import io.github.mthli.dara.widget.holder.FilterHolder; 12 | import io.github.mthli.dara.widget.holder.LabelHolder; 13 | import io.github.mthli.dara.widget.holder.NoticeHolder; 14 | import io.github.mthli.dara.widget.holder.SpaceHolder; 15 | import io.github.mthli.dara.widget.item.Filter; 16 | import io.github.mthli.dara.widget.item.Label; 17 | import io.github.mthli.dara.widget.item.Notice; 18 | import io.github.mthli.dara.widget.item.Space; 19 | 20 | public class DaraAdapter extends RecyclerView.Adapter { 21 | private static final int VIEW_TYPE_FILTER = 0x100; 22 | private static final int VIEW_TYPE_LABEL = 0x101; 23 | private static final int VIEW_TYPE_NOTICE = 0x102; 24 | private static final int VIEW_TYPE_SPACE = 0x103; 25 | 26 | private Context mContext; 27 | private List mList; 28 | 29 | public DaraAdapter(Context context, List list) { 30 | mContext = context; 31 | mList = list; 32 | } 33 | 34 | @Override 35 | public int getItemCount() { 36 | return mList.size(); 37 | } 38 | 39 | @Override 40 | public int getItemViewType(int position) { 41 | Object object = mList.get(position); 42 | 43 | if (object instanceof Filter) { 44 | return VIEW_TYPE_FILTER; 45 | } else if (object instanceof Label) { 46 | return VIEW_TYPE_LABEL; 47 | } else if (object instanceof Notice) { 48 | return VIEW_TYPE_NOTICE; 49 | } else { 50 | return VIEW_TYPE_SPACE; 51 | } 52 | } 53 | 54 | @Override 55 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 56 | switch (viewType) { 57 | case VIEW_TYPE_FILTER: 58 | return new FilterHolder(LayoutInflater.from(mContext) 59 | .inflate(R.layout.recycler_item_filter, parent, false)); 60 | case VIEW_TYPE_LABEL: 61 | return new LabelHolder(LayoutInflater.from(mContext) 62 | .inflate(R.layout.recycler_item_label, parent, false)); 63 | case VIEW_TYPE_NOTICE: 64 | return new NoticeHolder(LayoutInflater.from(mContext) 65 | .inflate(R.layout.reccyler_item_notice, parent, false)); 66 | default: 67 | return new SpaceHolder(LayoutInflater.from(mContext) 68 | .inflate(R.layout.recycler_item_space, parent, false)); 69 | } 70 | } 71 | 72 | @Override 73 | public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 74 | Object object = mList.get(position); 75 | 76 | switch (getItemViewType(position)) { 77 | case VIEW_TYPE_FILTER: 78 | ((FilterHolder) holder).setFilter((Filter) object); 79 | break; 80 | case VIEW_TYPE_LABEL: 81 | ((LabelHolder) holder).setLabel((Label) object); 82 | break; 83 | case VIEW_TYPE_NOTICE: 84 | ((NoticeHolder) holder).setNotice((Notice) object); 85 | break; 86 | case VIEW_TYPE_SPACE: 87 | ((SpaceHolder) holder).setSpace((Space) object); 88 | break; 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/app/MainActivity.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.app; 2 | 3 | import android.app.ActivityManager; 4 | import android.content.Intent; 5 | import android.graphics.BitmapFactory; 6 | import android.net.Uri; 7 | import android.os.Bundle; 8 | import android.support.customtabs.CustomTabsIntent; 9 | import android.support.v4.content.ContextCompat; 10 | import android.support.v7.app.AppCompatActivity; 11 | import android.view.Gravity; 12 | import android.widget.FrameLayout; 13 | 14 | import io.github.mthli.dara.R; 15 | import io.github.mthli.dara.event.RequestNotificationListEvent; 16 | import io.github.mthli.dara.util.RxBus; 17 | import io.github.mthli.dara.widget.RecyclerLayout; 18 | import io.github.mthli.dara.widget.PermissionLayout; 19 | 20 | public class MainActivity extends AppCompatActivity 21 | implements PermissionLayout.PermissionLayoutListener { 22 | private FrameLayout mContainer; 23 | private boolean isFirstResume; 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_main); 29 | setupTaskDescription(); 30 | 31 | mContainer = (FrameLayout) findViewById(R.id.container); 32 | isFirstResume = true; 33 | } 34 | 35 | private void setupTaskDescription() { 36 | setTaskDescription(new ActivityManager.TaskDescription( 37 | getString(R.string.app_name), 38 | BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher), 39 | ContextCompat.getColor(MainActivity.this, R.color.white) 40 | )); 41 | } 42 | 43 | @Override 44 | public void onResume() { 45 | super.onResume(); 46 | 47 | if (!DaraService.sIsAlive) { 48 | setupWhenPermissionDenied(); 49 | } else if (isFirstResume) { 50 | setupWhenPermissionGrant(); 51 | isFirstResume = false; 52 | } else { 53 | RxBus.getInstance().post(new RequestNotificationListEvent()); 54 | } 55 | } 56 | 57 | private void setupWhenPermissionDenied() { 58 | PermissionLayout layout = (PermissionLayout) getLayoutInflater() 59 | .inflate(R.layout.layout_permission, null, false); 60 | layout.setPermissionLayoutListener(this); 61 | mContainer.removeAllViews(); 62 | mContainer.addView(layout, buildLayoutParams()); 63 | } 64 | 65 | @Override 66 | public void onPositionClick() { 67 | Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"); 68 | startActivity(intent); 69 | } 70 | 71 | @Override 72 | public void onNegativeClick() { 73 | finish(); 74 | } 75 | 76 | @Override 77 | public void onNeutralClick() { 78 | CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); 79 | builder.setToolbarColor(ContextCompat.getColor(this, R.color.blue_grey_900)); 80 | builder.build().launchUrl(this, 81 | Uri.parse("https://support.google.com/nexus/answer/6111294")); 82 | } 83 | 84 | private void setupWhenPermissionGrant() { 85 | RecyclerLayout layout = (RecyclerLayout) getLayoutInflater() 86 | .inflate(R.layout.layout_recycler, null, false); 87 | mContainer.removeAllViews(); 88 | mContainer.addView(layout, buildLayoutParams()); 89 | } 90 | 91 | private FrameLayout.LayoutParams buildLayoutParams() { 92 | FrameLayout.LayoutParams params = new FrameLayout.LayoutParams( 93 | FrameLayout.LayoutParams.MATCH_PARENT, 94 | FrameLayout.LayoutParams.MATCH_PARENT); 95 | params.gravity = Gravity.CENTER; 96 | return params; 97 | } 98 | } -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_edit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 12 | 13 | 14 | 16 | 17 | 25 | 26 | 27 | 38 | 39 | 40 | 41 | 42 | 47 | 48 | 49 | 51 | 52 | 64 | 65 | 66 | 81 | 82 | 83 | 84 | 85 | 90 | 91 | 92 | 94 | 95 | 107 | 108 | 109 | 124 | 125 | 126 | 127 | 128 | 133 | 134 | 135 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/app/DaraService.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.app; 2 | 3 | import android.app.Notification; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.os.IBinder; 7 | import android.service.notification.NotificationListenerService; 8 | import android.service.notification.StatusBarNotification; 9 | import android.text.TextUtils; 10 | 11 | import com.orm.query.Select; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import java.util.regex.Matcher; 16 | import java.util.regex.Pattern; 17 | 18 | import io.github.mthli.dara.event.NotificationRemovedEvent; 19 | import io.github.mthli.dara.event.ResponseNotificationListEvent; 20 | import io.github.mthli.dara.event.RequestNotificationListEvent; 21 | import io.github.mthli.dara.event.UpdateRecordEvent; 22 | import io.github.mthli.dara.record.Record; 23 | import io.github.mthli.dara.util.RegExUtils; 24 | import io.github.mthli.dara.util.RxBus; 25 | import rx.Subscriber; 26 | import rx.Subscription; 27 | import rx.subscriptions.CompositeSubscription; 28 | 29 | public class DaraService extends NotificationListenerService { 30 | public static boolean sIsAlive; 31 | 32 | private List mRecordList; 33 | private CompositeSubscription mSubscription; 34 | 35 | @Override 36 | public IBinder onBind(Intent intent) { 37 | sIsAlive = true; 38 | 39 | mRecordList = Select.from(Record.class).list(); 40 | if (mSubscription != null) { 41 | mSubscription.unsubscribe(); 42 | } 43 | mSubscription = new CompositeSubscription(); 44 | 45 | setupRxBus(); 46 | return super.onBind(intent); 47 | } 48 | 49 | private void setupRxBus() { 50 | Subscription subscription = RxBus.getInstance() 51 | .toObservable(RequestNotificationListEvent.class) 52 | .subscribe(new Subscriber() { 53 | @Override 54 | public void onCompleted() { 55 | // DO NOTHING 56 | } 57 | 58 | @Override 59 | public void onError(Throwable e) { 60 | e.printStackTrace(); 61 | } 62 | 63 | @Override 64 | public void onNext(RequestNotificationListEvent event) { 65 | onRequestNotificationListEvent(); 66 | } 67 | }); 68 | mSubscription.add(subscription); 69 | 70 | subscription = RxBus.getInstance() 71 | .toObservable(UpdateRecordEvent.class) 72 | .subscribe(new Subscriber() { 73 | @Override 74 | public void onCompleted() { 75 | // DO NOTHING 76 | } 77 | 78 | @Override 79 | public void onError(Throwable e) { 80 | e.printStackTrace(); 81 | } 82 | 83 | @Override 84 | public void onNext(UpdateRecordEvent event) { 85 | onUpdateRecordEvent(); 86 | } 87 | }); 88 | mSubscription.add(subscription); 89 | } 90 | 91 | // Filter isOngoing() 92 | private void onRequestNotificationListEvent() { 93 | List list = new ArrayList<>(); 94 | List group = new ArrayList<>(); 95 | 96 | for (StatusBarNotification notification : getActiveNotifications()) { 97 | if (!notification.isOngoing() && !group.contains(notification.getGroupKey())) { 98 | group.add(notification.getGroupKey()); 99 | list.add(notification); 100 | } 101 | } 102 | 103 | RxBus.getInstance().post(new ResponseNotificationListEvent(list)); 104 | } 105 | 106 | private void onUpdateRecordEvent() { 107 | onRequestNotificationListEvent(); 108 | mRecordList = Select.from(Record.class).list(); 109 | } 110 | 111 | @Override 112 | public boolean onUnbind(Intent intent) { 113 | sIsAlive = false; 114 | 115 | mRecordList.clear(); 116 | if (mSubscription != null) { 117 | mSubscription.unsubscribe(); 118 | } 119 | 120 | return super.onUnbind(intent); 121 | } 122 | 123 | @Override 124 | public void onNotificationPosted(StatusBarNotification sbn) { 125 | filterNotification(sbn); 126 | onRequestNotificationListEvent(); 127 | } 128 | 129 | private void filterNotification(StatusBarNotification sbn) { 130 | for (Record record : mRecordList) { 131 | if (record.packageName.equals(sbn.getPackageName())) { 132 | if (record.isRegEx) { 133 | filterNotificationByRegEx(record, sbn); 134 | } else { 135 | filterNotificationByHashTags(record, sbn); 136 | } 137 | } 138 | } 139 | } 140 | 141 | private void filterNotificationByRegEx(Record record, StatusBarNotification sbn) { 142 | Bundle bundle = sbn.getNotification().extras; 143 | 144 | if (!TextUtils.isEmpty(record.title)) { 145 | String title = bundle.getString(Notification.EXTRA_TITLE); 146 | if (!TextUtils.isEmpty(title)) { 147 | Matcher matcher = Pattern.compile(record.title).matcher(title); 148 | if (matcher.matches()) { 149 | cancelNotification(sbn.getKey()); 150 | return; 151 | } 152 | } 153 | } 154 | 155 | if (!TextUtils.isEmpty(record.content)) { 156 | String content = bundle.getString(Notification.EXTRA_TEXT); 157 | if (!TextUtils.isEmpty(content)) { 158 | Matcher matcher = Pattern.compile(record.content).matcher(content); 159 | if (matcher.matches()) { 160 | cancelNotification(sbn.getKey()); 161 | } 162 | } 163 | } 164 | } 165 | 166 | private void filterNotificationByHashTags(Record record, StatusBarNotification sbn) { 167 | Bundle bundle = sbn.getNotification().extras; 168 | 169 | if (!TextUtils.isEmpty(record.title)) { 170 | String title = bundle.getString(Notification.EXTRA_TITLE); 171 | if (!TextUtils.isEmpty(title)) { 172 | for (String tag : RegExUtils.getHashTags(record.title)) { 173 | tag = tag.substring("#".length()); 174 | if (title.contains(tag)) { 175 | cancelNotification(sbn.getKey()); 176 | return; 177 | } 178 | } 179 | } 180 | } 181 | 182 | if (!TextUtils.isEmpty(record.content)) { 183 | String content = bundle.getString(Notification.EXTRA_TEXT); 184 | if (!TextUtils.isEmpty(content)) { 185 | for (String tag : RegExUtils.getHashTags(record.content)) { 186 | tag = tag.substring("#".length()); 187 | if (content.contains(tag)) { 188 | cancelNotification(sbn.getKey()); 189 | break; 190 | } 191 | } 192 | } 193 | } 194 | } 195 | 196 | @Override 197 | public void onNotificationRankingUpdate(RankingMap rankingMap) { 198 | onRequestNotificationListEvent(); 199 | } 200 | 201 | @Override 202 | public void onNotificationRemoved(StatusBarNotification sbn) { 203 | onRequestNotificationListEvent(); 204 | RxBus.getInstance().post(new NotificationRemovedEvent(sbn)); 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/EditLayout.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.content.ContextCompat; 6 | import android.support.v7.widget.AppCompatEditText; 7 | import android.support.v7.widget.AppCompatTextView; 8 | import android.support.v7.widget.SwitchCompat; 9 | import android.text.Editable; 10 | import android.text.TextUtils; 11 | import android.text.TextWatcher; 12 | import android.util.AttributeSet; 13 | import android.widget.CompoundButton; 14 | import android.widget.LinearLayout; 15 | import android.widget.Toast; 16 | 17 | import java.util.List; 18 | 19 | import io.github.mthli.dara.R; 20 | import io.github.mthli.dara.app.EditActivity; 21 | import io.github.mthli.dara.util.RegExUtils; 22 | 23 | public class EditLayout extends LinearLayout implements CompoundButton.OnCheckedChangeListener, 24 | ButtonBarLayout.ButtonBarLayoutListener { 25 | public interface EditLayoutListener { 26 | void onHashTagsReady(List titleTags, List contentTags); 27 | void onRegExReady(String titleRegEx, String contentRegEx); 28 | } 29 | 30 | private static final int TITLE_COUNT_MAX = 20; 31 | private static final int TITLE_COUNT_MIN = 0; 32 | private static final int TITLE_COUNT_LIMIT = 5; 33 | private static final int CONTENT_COUNT_MAX = 20; 34 | private static final int CONTENT_COUNT_MIN = 0; 35 | private static final int CONTENT_COUNT_LIMIT = 5; 36 | 37 | private SwitchCompat mSwitchCompat; 38 | private AppCompatEditText mTitleView; 39 | private AppCompatTextView mTitleCount; 40 | private AppCompatEditText mContentView; 41 | private AppCompatTextView mContentCount; 42 | 43 | private EditLayoutListener mEditLayoutListener; 44 | private boolean mIsRegExMode; 45 | 46 | public EditLayout(Context context) { 47 | super(context); 48 | } 49 | 50 | public EditLayout(Context context, @Nullable AttributeSet attrs) { 51 | super(context, attrs); 52 | } 53 | 54 | public EditLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 55 | super(context, attrs, defStyleAttr); 56 | } 57 | 58 | public void setEditLayoutListener(EditLayoutListener editLayoutListener) { 59 | mEditLayoutListener = editLayoutListener; 60 | } 61 | 62 | public void setInfo(boolean isRegEx, String title, String content) { 63 | mSwitchCompat.setChecked(isRegEx); 64 | mTitleView.setText(title); 65 | mTitleView.setSelection(mTitleView.length()); 66 | mContentView.setText(content); 67 | mContentView.setSelection(mContentView.length()); 68 | } 69 | 70 | @Override 71 | protected void onFinishInflate() { 72 | super.onFinishInflate(); 73 | 74 | mTitleView = (AppCompatEditText) findViewById(R.id.title); 75 | mTitleCount = (AppCompatTextView) findViewById(R.id.title_count); 76 | mContentView = (AppCompatEditText) findViewById(R.id.content); 77 | mContentCount = (AppCompatTextView) findViewById(R.id.content_count); 78 | mSwitchCompat = (SwitchCompat) findViewById(R.id.switch_regular); 79 | ButtonBarLayout buttonBarLayout = (ButtonBarLayout) findViewById(R.id.button_bar); 80 | 81 | setupTitleView(); 82 | setupContentView(); 83 | mSwitchCompat.setOnCheckedChangeListener(this); 84 | buttonBarLayout.setButtonBarLayoutListener(this); 85 | } 86 | 87 | private void setupTitleView() { 88 | mTitleView.setHint(R.string.hint_title_separator); 89 | mTitleCount.setText(String.valueOf(TITLE_COUNT_MAX)); 90 | mTitleView.addTextChangedListener(new TextWatcher() { 91 | @Override 92 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 93 | // DO NOTHING 94 | } 95 | 96 | @Override 97 | public void onTextChanged(CharSequence s, int start, int before, int count) { 98 | // DO NOTHING 99 | } 100 | 101 | @Override 102 | public void afterTextChanged(Editable s) { 103 | int count = TITLE_COUNT_MAX - s.length(); 104 | if (count <= TITLE_COUNT_LIMIT) { 105 | mTitleCount.setTextColor(ContextCompat 106 | .getColor(getContext(), R.color.red_500)); 107 | } else { 108 | mTitleCount.setTextColor(ContextCompat 109 | .getColor(getContext(), R.color.text_hint)); 110 | } 111 | mTitleCount.setText(String.valueOf(count)); 112 | } 113 | }); 114 | } 115 | 116 | private void setupContentView() { 117 | mContentView.setHint(R.string.hint_content_separator); 118 | mContentCount.setText(String.valueOf(CONTENT_COUNT_MAX)); 119 | mContentView.addTextChangedListener(new TextWatcher() { 120 | @Override 121 | public void beforeTextChanged(CharSequence s, int start, int count, int after) { 122 | // DO NOTHING 123 | } 124 | 125 | @Override 126 | public void onTextChanged(CharSequence s, int start, int before, int count) { 127 | // DO NOTHING 128 | } 129 | 130 | @Override 131 | public void afterTextChanged(Editable s) { 132 | int count = CONTENT_COUNT_MAX - s.length(); 133 | if (count <= CONTENT_COUNT_LIMIT) { 134 | mContentCount.setTextColor(ContextCompat 135 | .getColor(getContext(), R.color.red_500)); 136 | } else { 137 | mContentCount.setTextColor(ContextCompat 138 | .getColor(getContext(), R.color.text_hint)); 139 | } 140 | mContentCount.setText(String.valueOf(count)); 141 | } 142 | }); 143 | } 144 | 145 | @Override 146 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 147 | mTitleView.setHint(isChecked ? R.string.hint_title_regular 148 | : R.string.hint_title_separator); 149 | mContentView.setHint(isChecked ? R.string.hint_content_regular 150 | : R.string.hint_content_separator); 151 | mIsRegExMode = isChecked; 152 | } 153 | 154 | @Override 155 | public void onPositiveButtonClick() { 156 | if (mIsRegExMode) { 157 | onRegExMode(); 158 | } else { 159 | onHashTagsMode(); 160 | } 161 | } 162 | 163 | private void onHashTagsMode() { 164 | String title = mTitleView.getText().toString().trim(); 165 | if (!TextUtils.isEmpty(title) && RegExUtils.getHashTags(title).isEmpty()) { 166 | Toast.makeText(getContext(), R.string.toast_rule_title_error, 167 | Toast.LENGTH_SHORT).show(); 168 | return; 169 | } else if (TITLE_COUNT_MAX - title.length() < TITLE_COUNT_MIN) { 170 | Toast.makeText(getContext(), R.string.toast_rule_title_count, 171 | Toast.LENGTH_SHORT).show(); 172 | return; 173 | } 174 | 175 | String content = mContentView.getText().toString().trim(); 176 | if (!TextUtils.isEmpty(content) && RegExUtils.getHashTags(content).isEmpty()) { 177 | Toast.makeText(getContext(), R.string.toast_rule_content_error, 178 | Toast.LENGTH_SHORT).show(); 179 | return; 180 | } else if (CONTENT_COUNT_MAX - content.length() < CONTENT_COUNT_MIN) { 181 | Toast.makeText(getContext(), R.string.toast_rule_content_count, 182 | Toast.LENGTH_SHORT).show(); 183 | return; 184 | } 185 | 186 | if (RegExUtils.getHashTags(title).isEmpty() 187 | && RegExUtils.getHashTags(content).isEmpty()) { 188 | Toast.makeText(getContext(), R.string.toast_rule_title_content_error, 189 | Toast.LENGTH_SHORT).show(); 190 | return; 191 | } 192 | 193 | if (mEditLayoutListener != null) { 194 | mEditLayoutListener.onHashTagsReady(RegExUtils.getHashTags(title), 195 | RegExUtils.getHashTags(content)); 196 | } 197 | } 198 | 199 | private void onRegExMode() { 200 | String title = mTitleView.getText().toString().trim(); 201 | if (!TextUtils.isEmpty(title) && !RegExUtils.isRegEx(title)) { 202 | Toast.makeText(getContext(), R.string.toast_rule_title_error, 203 | Toast.LENGTH_SHORT).show(); 204 | return; 205 | } else if (TITLE_COUNT_MAX - title.length() < TITLE_COUNT_MIN) { 206 | Toast.makeText(getContext(), R.string.toast_rule_title_count, 207 | Toast.LENGTH_SHORT).show(); 208 | return; 209 | } 210 | 211 | String content = mContentView.getText().toString().trim(); 212 | if (!TextUtils.isEmpty(content) && !RegExUtils.isRegEx(content)) { 213 | Toast.makeText(getContext(), R.string.toast_rule_content_error, 214 | Toast.LENGTH_SHORT).show(); 215 | return; 216 | } else if (CONTENT_COUNT_MAX - content.length() < CONTENT_COUNT_MIN) { 217 | Toast.makeText(getContext(), R.string.toast_rule_content_count, 218 | Toast.LENGTH_SHORT).show(); 219 | return; 220 | } 221 | 222 | if (!RegExUtils.isRegEx(title) && !RegExUtils.isRegEx(content)) { 223 | Toast.makeText(getContext(), R.string.toast_rule_title_content_error, 224 | Toast.LENGTH_SHORT).show(); 225 | return; 226 | } 227 | 228 | if (mEditLayoutListener != null) { 229 | mEditLayoutListener.onRegExReady(title, content); 230 | } 231 | } 232 | 233 | @Override 234 | public void onNegativeButtonClick() { 235 | ((EditActivity) getContext()).onBackPressed(); 236 | } 237 | 238 | @Override 239 | public void onNeutralButtonClick() { 240 | // TODO 241 | } 242 | } 243 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/app/EditActivity.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.app; 2 | 3 | import android.app.ActivityManager; 4 | import android.content.Intent; 5 | import android.content.pm.ApplicationInfo; 6 | import android.graphics.Bitmap; 7 | import android.graphics.BitmapFactory; 8 | import android.graphics.drawable.BitmapDrawable; 9 | import android.graphics.drawable.Drawable; 10 | import android.os.Bundle; 11 | import android.support.v4.content.ContextCompat; 12 | import android.support.v4.view.ViewCompat; 13 | import android.support.v7.app.AppCompatActivity; 14 | import android.support.v7.widget.Toolbar; 15 | import android.text.TextUtils; 16 | import android.view.Menu; 17 | import android.view.MenuItem; 18 | import android.view.View; 19 | import android.widget.Toast; 20 | 21 | import java.util.List; 22 | 23 | import io.github.mthli.dara.R; 24 | import io.github.mthli.dara.event.NotificationRemovedEvent; 25 | import io.github.mthli.dara.event.UpdateRecordEvent; 26 | import io.github.mthli.dara.record.Record; 27 | import io.github.mthli.dara.util.AppInfoUtils; 28 | import io.github.mthli.dara.util.DisplayUtils; 29 | import io.github.mthli.dara.util.RxBus; 30 | import io.github.mthli.dara.widget.EditLayout; 31 | import rx.Observable; 32 | import rx.Subscriber; 33 | import rx.Subscription; 34 | import rx.android.schedulers.AndroidSchedulers; 35 | 36 | public class EditActivity extends AppCompatActivity 37 | implements View.OnClickListener, EditLayout.EditLayoutListener { 38 | public static final String EXTRA_PACKAGE_NAME = "EXTRA_PACKAGE_NAME"; 39 | public static final String EXTRA_IS_REG_EX = "EXTRA_IS_REG_EX"; 40 | public static final String EXTRA_TITLE = "EXTRA_TITLE"; 41 | public static final String EXTRA_CONTENT = "EXTRA_CONTENT"; 42 | public static final String EXTRA_RECORD_ID = "EXTRA_RECORD_ID"; 43 | 44 | private String mPackageName; 45 | private boolean mIsRegEx; 46 | private String mTitle; 47 | private String mContent; 48 | private long mRecordId; 49 | 50 | private Subscription mRemovedSubscription; 51 | 52 | @Override 53 | protected void onCreate(Bundle savedInstanceState) { 54 | super.onCreate(savedInstanceState); 55 | setContentView(R.layout.activity_edit); 56 | setFinishOnTouchOutside(false); 57 | setupTaskDescription(); 58 | 59 | mPackageName = getIntent().getStringExtra(EXTRA_PACKAGE_NAME); 60 | mIsRegEx = getIntent().getBooleanExtra(EXTRA_IS_REG_EX, false); 61 | mTitle = getIntent().getStringExtra(EXTRA_TITLE); 62 | mContent = getIntent().getStringExtra(EXTRA_CONTENT); 63 | mRecordId = getIntent().getLongExtra(EXTRA_RECORD_ID, -1L); 64 | 65 | setupToolbar(); 66 | setupEditLayout(); 67 | setupRxBus(); 68 | } 69 | 70 | private void setupTaskDescription() { 71 | setTaskDescription(new ActivityManager.TaskDescription( 72 | getString(R.string.app_name), 73 | BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher), 74 | ContextCompat.getColor(EditActivity.this, R.color.white) 75 | )); 76 | } 77 | 78 | private void setupToolbar() { 79 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 80 | 81 | setSupportActionBar(toolbar); 82 | toolbar.setTitleTextAppearance(this, R.style.ToolbarTitleAppearance); 83 | toolbar.setSubtitleTextAppearance(this, R.style.ToolbarSubtitleAppearance); 84 | ViewCompat.setElevation(toolbar, 0.0f); 85 | 86 | CharSequence appName = AppInfoUtils.getAppLabel(this, mPackageName); 87 | getSupportActionBar().setTitle(appName); 88 | getSupportActionBar().setSubtitle(AppInfoUtils.isSystemApp(this, mPackageName) 89 | ? R.string.subtitle_system_app : R.string.subtitle_user_app); 90 | 91 | Drawable appIcon = AppInfoUtils.getAppIcon(this, mPackageName); 92 | if (appIcon != null && appIcon instanceof BitmapDrawable) { 93 | int dp30 = (int) DisplayUtils.dp2px(this, 30.0f); 94 | Bitmap bitmap = ((BitmapDrawable) appIcon).getBitmap(); 95 | Bitmap resize = Bitmap.createScaledBitmap(bitmap, dp30, dp30, false); 96 | appIcon = new BitmapDrawable(getResources(), resize); 97 | toolbar.setNavigationIcon(appIcon); 98 | toolbar.setNavigationOnClickListener(this); 99 | } 100 | } 101 | 102 | private void setupEditLayout() { 103 | EditLayout layout = (EditLayout) findViewById(R.id.edit); 104 | layout.setEditLayoutListener(this); 105 | layout.setInfo(mIsRegEx, mTitle, mContent); 106 | } 107 | 108 | private void setupRxBus() { 109 | mRemovedSubscription = RxBus.getInstance() 110 | .toObservable(NotificationRemovedEvent.class) 111 | .observeOn(AndroidSchedulers.mainThread()) 112 | .subscribe(new Subscriber() { 113 | @Override 114 | public void onCompleted() { 115 | // DO NOTHING 116 | } 117 | 118 | @Override 119 | public void onError(Throwable e) { 120 | e.printStackTrace(); 121 | } 122 | 123 | @Override 124 | public void onNext(NotificationRemovedEvent event) { 125 | onNotificationRemovedEvent(event); 126 | } 127 | }); 128 | } 129 | 130 | private void onNotificationRemovedEvent(NotificationRemovedEvent event) { 131 | if (event.getStatusBarNotification().getPackageName().equals(mPackageName)) { 132 | if (event.getStatusBarNotification().getId() 133 | == event.getStatusBarNotification().getId()) { 134 | onBackPressed(); 135 | } 136 | } 137 | } 138 | 139 | @Override 140 | public boolean onCreateOptionsMenu(Menu menu) { 141 | getMenuInflater().inflate(R.menu.menu_dara, menu); 142 | return true; 143 | } 144 | 145 | @Override 146 | public boolean onOptionsItemSelected(MenuItem item) { 147 | switch (item.getItemId()) { 148 | case R.id.menu_settings: 149 | onClick(null); 150 | break; 151 | default: 152 | break; 153 | } 154 | 155 | return true; 156 | } 157 | 158 | @Override 159 | public void onClick(View view) { 160 | ApplicationInfo info = AppInfoUtils.getAppInfo(this, mPackageName); 161 | if (info == null) { 162 | return; 163 | } 164 | 165 | Intent intent = new Intent("android.settings.APP_NOTIFICATION_SETTINGS"); 166 | intent.putExtra("app_package", mPackageName); 167 | intent.putExtra("app_uid", info.uid); 168 | startActivity(intent); 169 | onBackPressed(); 170 | } 171 | 172 | @Override 173 | public void onHashTagsReady(final List titleTags, final List contentTags) { 174 | Observable.create( 175 | new Observable.OnSubscribe() { 176 | @Override 177 | public void call(Subscriber subscriber) { 178 | Record record = new Record(); 179 | if (mRecordId >= 0) { 180 | record.setId(mRecordId); 181 | } 182 | record.packageName = mPackageName; 183 | record.isRegEx = false; 184 | record.title = TextUtils.join(" ", titleTags); 185 | record.content = TextUtils.join(" ", contentTags); 186 | record.save(); 187 | subscriber.onNext(0); 188 | subscriber.onCompleted(); 189 | } 190 | }) 191 | .observeOn(AndroidSchedulers.mainThread()) 192 | .subscribe(new Subscriber() { 193 | @Override 194 | public void onCompleted() { 195 | // DO NOTHING 196 | } 197 | 198 | @Override 199 | public void onError(Throwable e) { 200 | e.printStackTrace(); 201 | Toast.makeText(EditActivity.this, R.string.toast_action_failed, 202 | Toast.LENGTH_SHORT).show(); 203 | } 204 | 205 | @Override 206 | public void onNext(Integer integer) { 207 | Toast.makeText(EditActivity.this, R.string.toast_action_successful, 208 | Toast.LENGTH_SHORT).show(); 209 | RxBus.getInstance().post(new UpdateRecordEvent()); 210 | finish(); 211 | } 212 | }); 213 | } 214 | 215 | @Override 216 | public void onRegExReady(final String titleRegEx, final String contentRegEx) { 217 | Observable.create( 218 | new Observable.OnSubscribe() { 219 | @Override 220 | public void call(Subscriber subscriber) { 221 | Record record = new Record(); 222 | if (mRecordId >= 0) { 223 | record.setId(mRecordId); 224 | } 225 | record.packageName = mPackageName; 226 | record.isRegEx = true; 227 | record.title = titleRegEx; 228 | record.content = contentRegEx; 229 | record.save(); 230 | subscriber.onNext(0); 231 | subscriber.onCompleted(); 232 | } 233 | }) 234 | .observeOn(AndroidSchedulers.mainThread()) 235 | .subscribe(new Subscriber() { 236 | @Override 237 | public void onCompleted() { 238 | // DO NOTHING 239 | } 240 | 241 | @Override 242 | public void onError(Throwable e) { 243 | e.printStackTrace(); 244 | Toast.makeText(EditActivity.this, R.string.toast_action_failed, 245 | Toast.LENGTH_SHORT).show(); 246 | } 247 | 248 | @Override 249 | public void onNext(Integer integer) { 250 | Toast.makeText(EditActivity.this, R.string.toast_action_successful, 251 | Toast.LENGTH_SHORT).show(); 252 | RxBus.getInstance().post(new UpdateRecordEvent()); 253 | finish(); 254 | } 255 | }); 256 | } 257 | 258 | @Override 259 | public void onDestroy() { 260 | super.onDestroy(); 261 | 262 | if (mRemovedSubscription != null) { 263 | mRemovedSubscription.unsubscribe(); 264 | } 265 | } 266 | } 267 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2016 Matthew Lee 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/CustomMenuSheetView.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.os.Build; 6 | import android.support.annotation.MenuRes; 7 | import android.support.annotation.Nullable; 8 | import android.support.annotation.StringRes; 9 | import android.support.v4.view.ViewCompat; 10 | import android.support.v7.view.SupportMenuInflater; 11 | import android.support.v7.view.menu.MenuBuilder; 12 | import android.text.TextUtils; 13 | import android.view.LayoutInflater; 14 | import android.view.Menu; 15 | import android.view.MenuItem; 16 | import android.view.SubMenu; 17 | import android.view.View; 18 | import android.view.ViewGroup; 19 | import android.widget.AbsListView; 20 | import android.widget.AdapterView; 21 | import android.widget.BaseAdapter; 22 | import android.widget.FrameLayout; 23 | import android.widget.GridView; 24 | import android.widget.ImageView; 25 | import android.widget.TextView; 26 | 27 | import java.util.ArrayList; 28 | 29 | import io.github.mthli.dara.R; 30 | import io.github.mthli.dara.util.DisplayUtils; 31 | 32 | /** 33 | * A SheetView that can represent a menu resource as a list or grid. 34 | *

35 | * A list can support submenus, and will include a divider and header for them where appropriate. 36 | * Grids currently don't support submenus, and don't in the Material Design spec either. 37 | *

38 | */ 39 | @SuppressLint("ViewConstructor") 40 | public class CustomMenuSheetView extends FrameLayout { 41 | /** 42 | * A listener for menu item clicks in the sheet 43 | */ 44 | public interface OnMenuItemClickListener { 45 | boolean onMenuItemClick(MenuItem item); 46 | } 47 | 48 | /** 49 | * The supported display types for the menu items. 50 | */ 51 | public enum MenuType {LIST, GRID} 52 | 53 | private Menu menu; 54 | private final MenuType menuType; 55 | private ArrayList items = new ArrayList<>(); 56 | private Adapter adapter; 57 | private AbsListView absListView; 58 | private final TextView titleView; 59 | protected final int originalListPaddingTop; 60 | private int columnWidthDp = 100; 61 | 62 | /** 63 | * @param context Context to construct the view with 64 | * @param menuType LIST or GRID 65 | * @param titleRes String resource ID for the title 66 | * @param listener Listener for menu item clicks in the sheet 67 | */ 68 | public CustomMenuSheetView(final Context context, final MenuType menuType, @StringRes final int titleRes, final OnMenuItemClickListener listener) { 69 | this(context, menuType, context.getString(titleRes), listener); 70 | } 71 | 72 | /** 73 | * @param context Context to construct the view with 74 | * @param menuType LIST or GRID 75 | * @param title Title for the sheet. Can be null 76 | * @param listener Listener for menu item clicks in the sheet 77 | */ 78 | public CustomMenuSheetView(final Context context, final MenuType menuType, @Nullable final CharSequence title, final OnMenuItemClickListener listener) { 79 | super(context); 80 | 81 | // Set up the menu 82 | this.menu = new MenuBuilder(context); 83 | this.menuType = menuType; 84 | 85 | // Inflate the appropriate view and set up the absListView 86 | inflate(context, menuType == MenuType.GRID ? flipboard.bottomsheet.commons.R.layout.grid_sheet_view : flipboard.bottomsheet.commons.R.layout.list_sheet_view, this); 87 | absListView = (AbsListView) findViewById(menuType == MenuType.GRID ? flipboard.bottomsheet.commons.R.id.grid : flipboard.bottomsheet.commons.R.id.list); 88 | if (listener != null) { 89 | absListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 90 | @Override 91 | public void onItemClick(AdapterView parent, View view, int position, long id) { 92 | listener.onMenuItemClick(adapter.getItem(position).getMenuItem()); 93 | } 94 | }); 95 | } 96 | 97 | // Set up the title 98 | titleView = (TextView) findViewById(flipboard.bottomsheet.commons.R.id.title); 99 | originalListPaddingTop = absListView.getPaddingTop(); 100 | setTitle(title); 101 | 102 | ViewCompat.setElevation(this, DisplayUtils.dp2px(getContext(), 16f)); 103 | } 104 | 105 | /** 106 | * Inflates a menu resource into the menu backing this sheet. 107 | * 108 | * @param menuRes Menu resource ID 109 | */ 110 | public void inflateMenu(@MenuRes int menuRes) { 111 | if (menuRes != -1) { 112 | SupportMenuInflater inflater = new SupportMenuInflater(getContext()); 113 | inflater.inflate(menuRes, menu); 114 | } 115 | 116 | prepareMenuItems(); 117 | } 118 | 119 | @Override 120 | protected void onAttachedToWindow() { 121 | super.onAttachedToWindow(); 122 | this.adapter = new Adapter(); 123 | absListView.setAdapter(this.adapter); 124 | } 125 | 126 | @Override 127 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 128 | int width = View.MeasureSpec.getSize(widthMeasureSpec); 129 | int dp480 = (int) DisplayUtils.dp2px(getContext(), 480.0f); 130 | width = width < dp480 ? width : dp480; 131 | 132 | if (menuType == MenuType.GRID) { 133 | float density = DisplayUtils.getDensity(getContext()); 134 | ((GridView) absListView).setNumColumns((int) (width / (columnWidthDp * density))); 135 | } 136 | 137 | widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY); 138 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); 139 | } 140 | 141 | @Override 142 | protected void onSizeChanged(int w, int h, int oldw, int oldh) { 143 | // Necessary for showing elevation on 5.0+ 144 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 145 | setOutlineProvider(new DisplayUtils.ShadowOutline(w, h)); 146 | } 147 | } 148 | 149 | /** 150 | * Flattens the visible menu items of {@link #menu} into {@link #items}, 151 | * while inserting separators between items when necessary. 152 | * 153 | * Adapted from the Design support library's NavigationMenuPresenter implementation 154 | */ 155 | private void prepareMenuItems() { 156 | items.clear(); 157 | int currentGroupId = 0; 158 | 159 | // Iterate over the menu items 160 | for (int i = 0; i < menu.size(); i++) { 161 | MenuItem item = menu.getItem(i); 162 | if (item.isVisible()) { 163 | if (item.hasSubMenu()) { 164 | // Flatten the submenu 165 | SubMenu subMenu = item.getSubMenu(); 166 | if (subMenu.hasVisibleItems()) { 167 | if (menuType == MenuType.LIST) { 168 | items.add(SheetMenuItem.SEPARATOR); 169 | 170 | // Add a header item if it has text 171 | if (!TextUtils.isEmpty(item.getTitle())) { 172 | items.add(SheetMenuItem.of(item)); 173 | } 174 | } 175 | 176 | // Add the sub-items 177 | for (int subI = 0, size = subMenu.size(); subI < size; subI++) { 178 | MenuItem subMenuItem = subMenu.getItem(subI); 179 | if (subMenuItem.isVisible()) { 180 | items.add(SheetMenuItem.of(subMenuItem)); 181 | } 182 | } 183 | 184 | // Add one more separator to the end to close it off if we have more items 185 | if (menuType == MenuType.LIST && i != menu.size() - 1) { 186 | items.add(SheetMenuItem.SEPARATOR); 187 | } 188 | } 189 | } else { 190 | int groupId = item.getGroupId(); 191 | if (groupId != currentGroupId && menuType == MenuType.LIST) { 192 | items.add(SheetMenuItem.SEPARATOR); 193 | } 194 | items.add(SheetMenuItem.of(item)); 195 | currentGroupId = groupId; 196 | } 197 | } 198 | } 199 | } 200 | 201 | /** 202 | * @return The current {@link Menu} instance backing this sheet. Note that this is mutable, and 203 | * you should call {@link #updateMenu()} after any changes. 204 | */ 205 | public Menu getMenu() { 206 | return this.menu; 207 | } 208 | 209 | /** 210 | * Invalidates the current internal representation of the menu and rebuilds it. Should be used 211 | * if the developer dynamically adds items to the Menu returned by {@link #getMenu()} 212 | */ 213 | public void updateMenu() { 214 | // Invalidate menu and rebuild it, useful if the user has dynamically added menu items. 215 | prepareMenuItems(); 216 | } 217 | 218 | /** 219 | * @return The {@link MenuType} this instance was built with 220 | */ 221 | public MenuType getMenuType() { 222 | return this.menuType; 223 | } 224 | 225 | /** 226 | * Sets the title text of the sheet 227 | * 228 | * @param resId String resource ID for the text 229 | */ 230 | public void setTitle(@StringRes int resId) { 231 | setTitle(getResources().getText(resId)); 232 | } 233 | 234 | /** 235 | * Sets the title text of the sheet 236 | * 237 | * @param title Title text to use 238 | */ 239 | public void setTitle(CharSequence title) { 240 | if (!TextUtils.isEmpty(title)) { 241 | titleView.setText(title); 242 | } else { 243 | titleView.setVisibility(GONE); 244 | 245 | // Add some padding to the top to account for the missing title 246 | absListView.setPadding(absListView.getPaddingLeft(), originalListPaddingTop + (int) DisplayUtils.dp2px(getContext(), 8f), absListView.getPaddingRight(), absListView.getPaddingBottom()); 247 | } 248 | } 249 | 250 | /** 251 | * Only applies to GRID 252 | */ 253 | public void setColumnWidthDp(int columnWidthDp) { 254 | this.columnWidthDp = columnWidthDp; 255 | } 256 | 257 | /** 258 | * @return The current title text of the sheet 259 | */ 260 | public CharSequence getTitle() { 261 | return titleView.getText(); 262 | } 263 | 264 | private class Adapter extends BaseAdapter { 265 | 266 | private static final int VIEW_TYPE_NORMAL = 0; 267 | private static final int VIEW_TYPE_SUBHEADER = 1; 268 | private static final int VIEW_TYPE_SEPARATOR = 2; 269 | 270 | private final LayoutInflater inflater; 271 | 272 | public Adapter() { 273 | this.inflater = LayoutInflater.from(getContext()); 274 | } 275 | 276 | @Override 277 | public int getCount() { 278 | return items.size(); 279 | } 280 | 281 | @Override 282 | public SheetMenuItem getItem(int position) { 283 | return items.get(position); 284 | } 285 | 286 | @Override 287 | public long getItemId(int position) { 288 | return position; 289 | } 290 | 291 | @Override 292 | public int getViewTypeCount() { 293 | return 3; 294 | } 295 | 296 | @Override 297 | public int getItemViewType(int position) { 298 | SheetMenuItem item = getItem(position); 299 | if (item.isSeparator()) { 300 | return VIEW_TYPE_SEPARATOR; 301 | } else if (item.getMenuItem().hasSubMenu()) { 302 | return VIEW_TYPE_SUBHEADER; 303 | } else { 304 | return VIEW_TYPE_NORMAL; 305 | } 306 | } 307 | 308 | @Override 309 | public View getView(int position, View convertView, ViewGroup parent) { 310 | 311 | SheetMenuItem item = getItem(position); 312 | int viewType = getItemViewType(position); 313 | 314 | switch (viewType) { 315 | case VIEW_TYPE_NORMAL: 316 | NormalViewHolder holder; 317 | if (convertView == null) { 318 | convertView = inflater.inflate(menuType == MenuType.GRID ? flipboard.bottomsheet.commons.R.layout.sheet_grid_item : R.layout.layout_item, parent, false); 319 | holder = new NormalViewHolder(convertView); 320 | convertView.setTag(holder); 321 | } else { 322 | holder = (NormalViewHolder) convertView.getTag(); 323 | } 324 | holder.bindView(item); 325 | break; 326 | case VIEW_TYPE_SUBHEADER: 327 | if (convertView == null) { 328 | convertView = inflater.inflate(flipboard.bottomsheet.commons.R.layout.sheet_list_item_subheader, parent, false); 329 | } 330 | TextView subHeader = (TextView) convertView; 331 | subHeader.setText(item.getMenuItem().getTitle()); 332 | break; 333 | case VIEW_TYPE_SEPARATOR: 334 | if (convertView == null) { 335 | convertView = inflater.inflate(flipboard.bottomsheet.commons.R.layout.sheet_list_item_separator, parent, false); 336 | } 337 | break; 338 | } 339 | 340 | return convertView; 341 | } 342 | 343 | @Override 344 | public boolean areAllItemsEnabled() { 345 | return false; 346 | } 347 | 348 | @Override 349 | public boolean isEnabled(int position) { 350 | return getItem(position).isEnabled(); 351 | } 352 | 353 | class NormalViewHolder { 354 | final ImageView icon; 355 | final TextView label; 356 | 357 | NormalViewHolder(View root) { 358 | icon = (ImageView) root.findViewById(flipboard.bottomsheet.commons.R.id.icon); 359 | label = (TextView) root.findViewById(flipboard.bottomsheet.commons.R.id.label); 360 | } 361 | 362 | public void bindView(SheetMenuItem item) { 363 | icon.setImageDrawable(item.getMenuItem().getIcon()); 364 | label.setText(item.getMenuItem().getTitle()); 365 | } 366 | } 367 | } 368 | 369 | private static class SheetMenuItem { 370 | 371 | private static final SheetMenuItem SEPARATOR = new SheetMenuItem(null); 372 | 373 | private final MenuItem menuItem; 374 | 375 | private SheetMenuItem(MenuItem item) { 376 | menuItem = item; 377 | } 378 | 379 | public static SheetMenuItem of(MenuItem item) { 380 | return new SheetMenuItem(item); 381 | } 382 | 383 | public boolean isSeparator() { 384 | return this == SEPARATOR; 385 | } 386 | 387 | public MenuItem getMenuItem() { 388 | return menuItem; 389 | } 390 | 391 | public boolean isEnabled() { 392 | // Separators and subheaders never respond to click 393 | return menuItem != null && !menuItem.hasSubMenu() && menuItem.isEnabled(); 394 | } 395 | 396 | } 397 | } 398 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/mthli/dara/widget/RecyclerLayout.java: -------------------------------------------------------------------------------- 1 | package io.github.mthli.dara.widget; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.res.Configuration; 6 | import android.os.Parcelable; 7 | import android.service.notification.StatusBarNotification; 8 | import android.support.annotation.Nullable; 9 | import android.support.v4.content.ContextCompat; 10 | import android.support.v7.widget.LinearLayoutManager; 11 | import android.text.TextUtils; 12 | import android.util.AttributeSet; 13 | import android.view.Gravity; 14 | import android.view.MenuItem; 15 | import android.widget.Toast; 16 | 17 | import com.flipboard.bottomsheet.BottomSheetLayout; 18 | import com.flipboard.bottomsheet.OnSheetDismissedListener; 19 | import com.orm.query.Select; 20 | import com.orm.util.NamingHelper; 21 | 22 | import java.util.ArrayList; 23 | import java.util.Collections; 24 | import java.util.Comparator; 25 | import java.util.HashSet; 26 | import java.util.List; 27 | 28 | import io.github.mthli.dara.R; 29 | import io.github.mthli.dara.app.EditActivity; 30 | import io.github.mthli.dara.event.ClickFilterEvent; 31 | import io.github.mthli.dara.event.ClickNoticeEvent; 32 | import io.github.mthli.dara.event.RequestNotificationListEvent; 33 | import io.github.mthli.dara.event.ResponseNotificationListEvent; 34 | import io.github.mthli.dara.event.UpdateRecordEvent; 35 | import io.github.mthli.dara.record.Record; 36 | import io.github.mthli.dara.util.AppInfoUtils; 37 | import io.github.mthli.dara.util.DisplayUtils; 38 | import io.github.mthli.dara.util.RxBus; 39 | import io.github.mthli.dara.widget.adapter.DaraAdapter; 40 | import io.github.mthli.dara.widget.item.Filter; 41 | import io.github.mthli.dara.widget.item.Label; 42 | import io.github.mthli.dara.widget.item.Notice; 43 | import io.github.mthli.dara.widget.item.Space; 44 | import rx.Observable; 45 | import rx.Subscriber; 46 | import rx.Subscription; 47 | import rx.android.schedulers.AndroidSchedulers; 48 | import rx.subscriptions.CompositeSubscription; 49 | 50 | public class RecyclerLayout extends BottomSheetLayout 51 | implements CustomMenuSheetView.OnMenuItemClickListener, OnSheetDismissedListener { 52 | private enum ClickType { 53 | EDIT, 54 | DELETE, 55 | NONE 56 | } 57 | private ClickType mClickType; 58 | 59 | private CustomMenuSheetView mMenuSheetView; 60 | private CustomViewTransformer mViewTransformer; 61 | private Record mRecord; 62 | 63 | private DaraAdapter mAdapter; 64 | private List mList; 65 | 66 | private CompositeSubscription mSubscription; 67 | 68 | public RecyclerLayout(Context context) { 69 | super(context); 70 | } 71 | 72 | public RecyclerLayout(Context context, @Nullable AttributeSet attrs) { 73 | super(context, attrs); 74 | } 75 | 76 | public RecyclerLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 77 | super(context, attrs, defStyleAttr); 78 | } 79 | 80 | @Override 81 | protected void onFinishInflate() { 82 | super.onFinishInflate(); 83 | 84 | setupMenuSheetView(); 85 | setupRecyclerView(); 86 | setupRxBus(); 87 | RxBus.getInstance().post(new RequestNotificationListEvent()); 88 | } 89 | 90 | @Override 91 | public void onConfigurationChanged(Configuration newConfig) { 92 | super.onConfigurationChanged(newConfig); 93 | 94 | mClickType = ClickType.NONE; 95 | removeOnSheetDismissedListener(this); 96 | dismissSheet(); 97 | } 98 | 99 | @Override 100 | public void onDetachedFromWindow() { 101 | super.onDetachedFromWindow(); 102 | 103 | removeOnSheetDismissedListener(this); 104 | if (mSubscription != null) { 105 | mSubscription.unsubscribe(); 106 | } 107 | } 108 | 109 | public void setupMenuSheetView() { 110 | mMenuSheetView = new CustomMenuSheetView(getContext(), 111 | CustomMenuSheetView.MenuType.LIST, null, this); 112 | mMenuSheetView.inflateMenu(R.menu.menu_sheet); 113 | mViewTransformer = new CustomViewTransformer(); 114 | } 115 | 116 | @Override 117 | public boolean onMenuItemClick(MenuItem item) { 118 | if (item.getItemId() == R.id.edit) { 119 | mClickType = ClickType.EDIT; 120 | } else if (item.getItemId() == R.id.delete) { 121 | mClickType = ClickType.DELETE; 122 | } else { 123 | mClickType = ClickType.NONE; 124 | } 125 | 126 | addOnSheetDismissedListener(this); 127 | dismissSheet(); 128 | return true; 129 | } 130 | 131 | @Override 132 | public void onDismissed(BottomSheetLayout layout) { 133 | if (mClickType == ClickType.EDIT) { 134 | onClickEdit(); 135 | } else if (mClickType == ClickType.DELETE) { 136 | onClickDelete(); 137 | } 138 | } 139 | 140 | private void onClickEdit() { 141 | Intent intent = new Intent(getContext(), EditActivity.class); 142 | intent.putExtra(EditActivity.EXTRA_PACKAGE_NAME, mRecord.packageName); 143 | intent.putExtra(EditActivity.EXTRA_IS_REG_EX, mRecord.isRegEx); 144 | if (mRecord.title != null) { 145 | intent.putExtra(EditActivity.EXTRA_TITLE, mRecord.title); 146 | } else { 147 | intent.putExtra(EditActivity.EXTRA_TITLE, (Parcelable[]) null); 148 | } 149 | if (mRecord.content != null) { 150 | intent.putExtra(EditActivity.EXTRA_CONTENT, mRecord.content); 151 | } else { 152 | intent.putExtra(EditActivity.EXTRA_TITLE, (Parcelable[]) null); 153 | } 154 | intent.putExtra(EditActivity.EXTRA_RECORD_ID, mRecord.getId()); 155 | getContext().startActivity(intent); 156 | } 157 | 158 | private void onClickDelete() { 159 | Observable.create( 160 | new Observable.OnSubscribe() { 161 | @Override 162 | public void call(Subscriber subscriber) { 163 | mRecord.delete(); 164 | subscriber.onNext(0); 165 | subscriber.onCompleted(); 166 | } 167 | }) 168 | .observeOn(AndroidSchedulers.mainThread()) 169 | .subscribe(new Subscriber() { 170 | @Override 171 | public void onCompleted() { 172 | // DO NOTHING 173 | } 174 | 175 | @Override 176 | public void onError(Throwable e) { 177 | e.printStackTrace(); 178 | Toast.makeText(getContext(), R.string.toast_action_failed, 179 | Toast.LENGTH_SHORT).show(); 180 | } 181 | 182 | @Override 183 | public void onNext(Integer integer) { 184 | RxBus.getInstance().post(new UpdateRecordEvent()); 185 | Toast.makeText(getContext(), R.string.toast_action_successful, 186 | Toast.LENGTH_SHORT).show(); 187 | } 188 | }); 189 | } 190 | 191 | private void setupRecyclerView() { 192 | mList = new ArrayList<>(); 193 | mAdapter = new DaraAdapter(getContext(), mList); 194 | 195 | CustomRecyclerView recyclerView = (CustomRecyclerView) findViewById(R.id.recycler); 196 | ((LayoutParams) recyclerView.getLayoutParams()).gravity = Gravity.CENTER; 197 | recyclerView.addItemDecoration(new DaraItemDecoration(getContext())); 198 | recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); 199 | recyclerView.setAdapter(mAdapter); 200 | } 201 | 202 | private void setupRxBus() { 203 | if (mSubscription != null) { 204 | mSubscription.unsubscribe(); 205 | } 206 | mSubscription = new CompositeSubscription(); 207 | 208 | Subscription subscription = RxBus.getInstance() 209 | .toObservable(ClickFilterEvent.class) 210 | .observeOn(AndroidSchedulers.mainThread()) 211 | .subscribe(new Subscriber() { 212 | @Override 213 | public void onCompleted() { 214 | // DO NOTHING 215 | } 216 | 217 | @Override 218 | public void onError(Throwable e) { 219 | e.printStackTrace(); 220 | } 221 | 222 | @Override 223 | public void onNext(ClickFilterEvent event) { 224 | onClickFilterEvent(event); 225 | } 226 | }); 227 | mSubscription.add(subscription); 228 | 229 | subscription = RxBus.getInstance() 230 | .toObservable(ClickNoticeEvent.class) 231 | .observeOn(AndroidSchedulers.mainThread()) 232 | .subscribe(new Subscriber() { 233 | @Override 234 | public void onCompleted() { 235 | // DO NOTHING 236 | } 237 | 238 | @Override 239 | public void onError(Throwable e) { 240 | e.printStackTrace(); 241 | } 242 | 243 | @Override 244 | public void onNext(ClickNoticeEvent event) { 245 | onClickNoticeEvent(event); 246 | } 247 | }); 248 | mSubscription.add(subscription); 249 | 250 | subscription = RxBus.getInstance() 251 | .toObservable(ResponseNotificationListEvent.class) 252 | .lift(new Observable.Operator, ResponseNotificationListEvent>() { 253 | @Override 254 | public Subscriber call(final Subscriber> subscriber) { 255 | return new Subscriber() { 256 | @Override 257 | public void onCompleted() { 258 | subscriber.onCompleted(); 259 | } 260 | 261 | @Override 262 | public void onError(Throwable e) { 263 | subscriber.onError(e); 264 | } 265 | 266 | @Override 267 | public void onNext(ResponseNotificationListEvent event) { 268 | subscriber.onNext(buildNoticeList(event)); 269 | } 270 | }; 271 | } 272 | }) 273 | .lift(new Observable.Operator, List>() { 274 | @Override 275 | public Subscriber> call(final Subscriber> subscriber) { 276 | return new Subscriber>() { 277 | @Override 278 | public void onCompleted() { 279 | subscriber.onCompleted(); 280 | } 281 | 282 | @Override 283 | public void onError(Throwable e) { 284 | subscriber.onError(e); 285 | } 286 | 287 | @Override 288 | public void onNext(List list) { 289 | subscriber.onNext(buildObjectList(list)); 290 | } 291 | }; 292 | } 293 | }) 294 | .observeOn(AndroidSchedulers.mainThread()) 295 | .subscribe(new Subscriber>() { 296 | @Override 297 | public void onCompleted() { 298 | // DO NOTHING 299 | } 300 | 301 | @Override 302 | public void onError(Throwable e) { 303 | e.printStackTrace(); 304 | } 305 | 306 | @Override 307 | public void onNext(List list) { 308 | // Simple and crude 309 | mList.clear(); 310 | mList.addAll(list); 311 | mAdapter.notifyDataSetChanged(); 312 | } 313 | }); 314 | mSubscription.add(subscription); 315 | } 316 | 317 | private void onClickFilterEvent(ClickFilterEvent event) { 318 | mRecord = event.getFilter().getRecord(); 319 | showWithSheetView(mMenuSheetView, mViewTransformer); 320 | } 321 | 322 | private void onClickNoticeEvent(ClickNoticeEvent event) { 323 | // Caused by: java.lang.RuntimeException: Not allowed to write file descriptors here 324 | StatusBarNotification notification = event.getNotice().getNotification().clone(); 325 | notification.getNotification().extras = null; 326 | // E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! 327 | notification.getNotification().bigContentView = null; 328 | notification.getNotification().headsUpContentView = null; 329 | 330 | Intent intent = new Intent(getContext(), EditActivity.class); 331 | intent.putExtra(EditActivity.EXTRA_PACKAGE_NAME, notification.getPackageName()); 332 | intent.putExtra(EditActivity.EXTRA_IS_REG_EX, false); 333 | intent.putExtra(EditActivity.EXTRA_TITLE, (Parcelable[]) null); 334 | intent.putExtra(EditActivity.EXTRA_CONTENT, (Parcelable[]) null); 335 | intent.putExtra(EditActivity.EXTRA_RECORD_ID, -1L); 336 | getContext().startActivity(intent); 337 | } 338 | 339 | private List buildNoticeList(ResponseNotificationListEvent event) { 340 | List list = new ArrayList<>(); 341 | 342 | for (StatusBarNotification notification : event.getStatusBarNotificationList()) { 343 | list.add(new Notice(notification)); 344 | } 345 | 346 | return list; 347 | } 348 | 349 | private List buildObjectList(List noticeList) { 350 | List objectList = new ArrayList<>(); 351 | objectList.add(new Space(DisplayUtils.getStatusBarHeight(getContext()))); 352 | 353 | if (noticeList.size() > 0) { 354 | objectList.add(new Label(getResources().getString(R.string.label_notification_center))); 355 | objectList.addAll(noticeList); 356 | } 357 | 358 | List recordList = Select.from(Record.class) 359 | .orderBy(NamingHelper.toSQLNameDefault("packageName")).list(); 360 | List packageList = new ArrayList<>(); 361 | for (Record record : recordList) { 362 | packageList.add(record.packageName); 363 | } 364 | HashSet labelSet = new HashSet<>(packageList); 365 | packageList.clear(); 366 | packageList.addAll(labelSet); 367 | Collections.sort(packageList, new Comparator() { 368 | @Override 369 | public int compare(String lhs, String rhs) { 370 | lhs = AppInfoUtils.getAppLabel(getContext(), lhs); 371 | rhs = AppInfoUtils.getAppLabel(getContext(), rhs); 372 | if (TextUtils.isEmpty(lhs) || TextUtils.isEmpty(rhs)) { 373 | return 0; 374 | } else { 375 | return lhs.compareTo(rhs); 376 | } 377 | } 378 | }); 379 | 380 | int hint = ContextCompat.getColor(getContext(), R.color.text_20p); 381 | int teal = ContextCompat.getColor(getContext(), R.color.teal_500); 382 | int i = 0; 383 | for (String packageName : packageList) { 384 | String packageLabel = AppInfoUtils.getAppLabel(getContext(), packageName); 385 | if (TextUtils.isEmpty(packageLabel)) { 386 | continue; 387 | } 388 | 389 | objectList.add(new Label(packageLabel)); 390 | for (Record record : recordList) { 391 | if (record.packageName.equals(packageName)) { 392 | Filter filter = new Filter(); 393 | filter.setColor(i++ % 2 == 0 ? hint : teal); 394 | filter.setRecord(record); 395 | objectList.add(filter); 396 | } 397 | } 398 | } 399 | 400 | return objectList; 401 | } 402 | } 403 | --------------------------------------------------------------------------------