diff options
author | Aaron Kling <webgeek1234@gmail.com> | 2017-12-05 13:22:19 -0600 |
---|---|---|
committer | Aaron Kling <webgeek1234@gmail.com> | 2017-12-05 13:22:19 -0600 |
commit | bd7bd0465dece4332c0860a8021ba83056ef0fa2 (patch) | |
tree | 69325bfd7f5c31e46836943cff1308de0cae96c5 | |
download | android_packages_apps_LineageCustomizer-bd7bd0465dece4332c0860a8021ba83056ef0fa2.tar.gz android_packages_apps_LineageCustomizer-bd7bd0465dece4332c0860a8021ba83056ef0fa2.tar.bz2 android_packages_apps_LineageCustomizer-bd7bd0465dece4332c0860a8021ba83056ef0fa2.zip |
Initial commit
WIP. Based off code by dhacker29
-rw-r--r-- | Android.mk | 10 | ||||
-rw-r--r-- | AndroidManifest.xml | 28 | ||||
-rw-r--r-- | proguard-project.txt | 20 | ||||
-rw-r--r-- | res/drawable-xhdpi/ic_launcher.png | bin | 0 -> 7433 bytes | |||
-rw-r--r-- | res/drawable-xhdpi/ic_title_custom.png | bin | 0 -> 1151 bytes | |||
-rw-r--r-- | res/values/colors.xml | 4 | ||||
-rw-r--r-- | res/values/config.xml | 28 | ||||
-rw-r--r-- | res/values/strings.xml | 11 | ||||
-rw-r--r-- | src/org/lineageos/partnercustomizer/PartnerReceiver.java | 132 | ||||
-rw-r--r-- | src/org/lineageos/partnercustomizer/TestActivity.java | 7 |
10 files changed, 240 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk new file mode 100644 index 0000000..351f29b --- /dev/null +++ b/Android.mk @@ -0,0 +1,10 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := $(call all-java-files-under, src) + +LOCAL_PACKAGE_NAME := LineageCustomizer +LOCAL_CERTIFICATE := platform +LOCAL_PRIVILEGED_MODULE := true + +include $(BUILD_PACKAGE) diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 0000000..d4bdecc --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="org.lineageos.partnercustomizer"> + + <uses-sdk + android:minSdkVersion="21" + android:targetSdkVersion="25" /> + + <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> + <uses-permission android:name="android.permission.INTERNET" /> + + <application android:label="@string/app_label"> + + <receiver android:name=".PartnerReceiver"> + <intent-filter> + <action android:name="com.google.android.leanbacklauncher.action.PARTNER_CUSTOMIZATION" /> + <category android:name="android.intent.category.DEFAULT" /> + </intent-filter> + + <intent-filter> + <action android:name="android.intent.action.PACKAGE_ADDED" /> + <action android:name="android.intent.action.PACKAGE_REMOVED" /> + <data android:scheme="package"/> + </intent-filter> + </receiver> + + </application> +</manifest> diff --git a/proguard-project.txt b/proguard-project.txt new file mode 100644 index 0000000..f2fe155 --- /dev/null +++ b/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/res/drawable-xhdpi/ic_launcher.png b/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..7bbd19a --- /dev/null +++ b/res/drawable-xhdpi/ic_launcher.png diff --git a/res/drawable-xhdpi/ic_title_custom.png b/res/drawable-xhdpi/ic_title_custom.png Binary files differnew file mode 100644 index 0000000..882579e --- /dev/null +++ b/res/drawable-xhdpi/ic_title_custom.png diff --git a/res/values/colors.xml b/res/values/colors.xml new file mode 100644 index 0000000..810e40e --- /dev/null +++ b/res/values/colors.xml @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <color name="partner_color">#FFFF00FF</color> +</resources> diff --git a/res/values/config.xml b/res/values/config.xml new file mode 100644 index 0000000..7179bf4 --- /dev/null +++ b/res/values/config.xml @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <!-- DO NOT TRANSLATE --> + <string name="partner_app_sorting_mode" translatable="false">fixed</string> + <!-- DO NOT TRANSLATE --> + <string name="partner_wallpaper" translatable="false">lineage_wallpaper</string> + <!-- DO NOT TRANSLATE --> + <string name="partner_widget_provider_component_name" translatable="false"> + com.cyanogenmod.lockclock/.ClockWidgetProvider + </string> + + <!-- DO NOT TRANSLATE --> + <string-array name="home_screen_row_ordering" translatable="false"> + <item>partner_row</item> + <item>games_row</item> + <item>apps_row</item> + <item>inputs_row</item> + <item>settings_row</item> + </string-array> + + <item type="drawable" name="partner_row_icon">@drawable/ic_title_custom</item> + + <!-- DO NOT TRANSLATE --> + <string name="partner_font" translatable="false">sans-serif-bold</string> + + <!-- DO NOT TRANSLATE --> + <string name="launcher_category" translatable="false">android.intent.category.LEANBACK_LAUNCHER</string> +</resources> diff --git a/res/values/strings.xml b/res/values/strings.xml new file mode 100644 index 0000000..930f32f --- /dev/null +++ b/res/values/strings.xml @@ -0,0 +1,11 @@ +<resources> + + <string name="app_label">LineageCustomizer</string> + + <string name="partner_row_title">Lineage Apps</string> + <string name="apps_row_title">Apps</string> + <string name="games_row_title">Games</string> + <string name="inputs_row_title">Inputs</string> + <string name="settings_row_title">Settings</string> + +</resources> diff --git a/src/org/lineageos/partnercustomizer/PartnerReceiver.java b/src/org/lineageos/partnercustomizer/PartnerReceiver.java new file mode 100644 index 0000000..6328957 --- /dev/null +++ b/src/org/lineageos/partnercustomizer/PartnerReceiver.java @@ -0,0 +1,132 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.lineageos.partnercustomizer; + +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.graphics.BitmapFactory; +import android.net.Uri; +import android.os.Bundle; +import android.os.Handler; + +/** + * This class posts notifications that are used to populate the Partner Row of the Leanback Launcher + * It also allows the system/launcher to find the correct partner customization + * package. + * + * Packages using this broadcast receiver must also be a system app to be used for + * partner customization. + */ +public class PartnerReceiver extends BroadcastReceiver { + private static final String ACTION_PARTNER_CUSTOMIZATION = + "com.google.android.leanbacklauncher.action.PARTNER_CUSTOMIZATION"; + + private static final String EXTRA_ROW_WRAPPING_CUTOFF = + "com.google.android.leanbacklauncher.extra.ROW_WRAPPING_CUTOFF"; + + private static final String PARTNER_GROUP = "partner_row_entry"; + private static final String BLACKLIST_PACKAGE = "com.google.android.leanbacklauncher.replacespackage"; + + private Context mContext; + private NotificationManager mNotifMan; + private PackageManager mPkgMan; + + // Cutoff value for when the Launcher displays the Partner row as a single + // row, or a two row grid. Can be used for correctly positioning the partner + // app entries. + private int mRowCutoff = 0; + + @Override + public void onReceive(Context context, Intent intent) { + if (mContext == null) { + mContext = context; + mNotifMan = (NotificationManager) + mContext.getSystemService(Context.NOTIFICATION_SERVICE); + mPkgMan = mContext.getPackageManager(); + } + + String action = intent.getAction(); + if (Intent.ACTION_PACKAGE_ADDED.equals(action)|| + Intent.ACTION_PACKAGE_REMOVED.equals(action)) { + postNotification(getPackageName(intent)); + } else if (ACTION_PARTNER_CUSTOMIZATION.equals(action)) { + mRowCutoff = intent.getIntExtra(EXTRA_ROW_WRAPPING_CUTOFF, 0); + } + } + + private void postNotification(String pkgName) { + int sort; + int resId; + int backupResId; + int titleId; + int backupTitleId; + + switch (pkgName) { + default: + return; + } + + postNotification(sort, resId, backupResId, titleId, backupTitleId, pkgName); + } + + private void postNotification(int sort, int resId, int backupResId, + int titleId, int backupTitleId, String pkgName) { + int id = resId; + Intent intent = mPkgMan.getLeanbackLaunchIntentForPackage(pkgName); + + if (intent == null) { + titleId = backupTitleId; + resId = backupResId; + intent = getBackupIntent(pkgName); + } + + Notification.Builder bob = new Notification.Builder(mContext); + Bundle extras = new Bundle(); + extras.putString(BLACKLIST_PACKAGE, pkgName); + + bob.setContentTitle(mContext.getString(titleId)) + .setSmallIcon(R.drawable.ic_launcher) + .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), resId)) + .setContentIntent(PendingIntent.getActivity(mContext, 0, intent, 0)) + .setCategory(Notification.CATEGORY_RECOMMENDATION) + .setGroup(PARTNER_GROUP) + .setSortKey(sort+"") + .setColor(mContext.getResources().getColor(R.color.partner_color)) + .setExtras(extras); + + mNotifMan.notify(id, bob.build()); + } + + private Intent getBackupIntent(String pkgName) { + Intent intent = new Intent(Intent.ACTION_VIEW); + intent.setData(Uri.parse("market://details?id=" + pkgName)); + + return intent; + } + + private String getPackageName(Intent intent) { + Uri uri = intent.getData(); + String pkg = uri != null ? uri.getSchemeSpecificPart() : null; + return pkg; + } + +} diff --git a/src/org/lineageos/partnercustomizer/TestActivity.java b/src/org/lineageos/partnercustomizer/TestActivity.java new file mode 100644 index 0000000..52fa721 --- /dev/null +++ b/src/org/lineageos/partnercustomizer/TestActivity.java @@ -0,0 +1,7 @@ +package org.lineageos.partnercustomizer; + +import android.app.Activity; + +public class TestActivity extends Activity { + +} |