diff options
author | Martin Brabham <optedoblivion@cyngn.com> | 2015-04-24 13:56:00 -0700 |
---|---|---|
committer | Michael Bestas <mkbestas@lineageos.org> | 2018-01-02 02:02:11 +0200 |
commit | 281ea21da6620b7657d24cb28a5c393bb4e81017 (patch) | |
tree | d480e53e3a87b606aca4f14a22763802ec6c1142 | |
parent | fb648753673546e3b30001fef558801f1e7959a5 (diff) | |
download | android_packages_apps_DeskClock-281ea21da6620b7657d24cb28a5c393bb4e81017.tar.gz android_packages_apps_DeskClock-281ea21da6620b7657d24cb28a5c393bb4e81017.tar.bz2 android_packages_apps_DeskClock-281ea21da6620b7657d24cb28a5c393bb4e81017.zip |
Make new menu entry to link to cLock widget settings.
[mikeioannina]: modified for O
Change-Id: I13ca3156c34eccdd8f60d8585281ae0585aac58e
-rw-r--r-- | res/values/cm_strings.xml | 21 | ||||
-rw-r--r-- | res/values/ids.xml | 1 | ||||
-rw-r--r-- | src/com/android/deskclock/DeskClock.java | 6 | ||||
-rw-r--r-- | src/com/android/deskclock/actionbarmenu/WidgetMenuItemController.java | 89 |
4 files changed, 115 insertions, 2 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml new file mode 100644 index 000000000..406988dfd --- /dev/null +++ b/res/values/cm_strings.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Copyright (C) 2012-2016 The CyanogenMod 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. +--> +<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"> + <!-- Setting title for accessing the cLock widget settings --> + <string name="menu_item_widget_settings">Widget settings</string> + +</resources> diff --git a/res/values/ids.xml b/res/values/ids.xml index cc8046819..6d5cf393b 100644 --- a/res/values/ids.xml +++ b/res/values/ids.xml @@ -21,4 +21,5 @@ <item name="menu_item_sort" type="id" /> <item name="menu_item_night_mode" type="id" /> <item name="menu_item_settings" type="id" /> + <item name="menu_item_widget_settings" type="id" /> </resources> diff --git a/src/com/android/deskclock/DeskClock.java b/src/com/android/deskclock/DeskClock.java index 6554a356c..5585956ee 100644 --- a/src/com/android/deskclock/DeskClock.java +++ b/src/com/android/deskclock/DeskClock.java @@ -44,6 +44,7 @@ import com.android.deskclock.actionbarmenu.MenuItemControllerFactory; import com.android.deskclock.actionbarmenu.NightModeMenuItemController; import com.android.deskclock.actionbarmenu.OptionsMenuManager; import com.android.deskclock.actionbarmenu.SettingsMenuItemController; +import com.android.deskclock.actionbarmenu.WidgetMenuItemController; import com.android.deskclock.data.DataModel; import com.android.deskclock.data.DataModel.SilentSetting; import com.android.deskclock.data.OnSilentSettingsListener; @@ -153,7 +154,8 @@ public class DeskClock extends BaseActivity // Configure the menu item controllers add behavior to the toolbar. mOptionsMenuManager.addMenuItemController( - new NightModeMenuItemController(this), new SettingsMenuItemController(this)); + new NightModeMenuItemController(this), new SettingsMenuItemController(this), + new WidgetMenuItemController(this)); mOptionsMenuManager.addMenuItemController( MenuItemControllerFactory.getInstance().buildMenuItemControllers(this)); @@ -677,4 +679,4 @@ public class DeskClock extends BaseActivity } } } -}
\ No newline at end of file +} diff --git a/src/com/android/deskclock/actionbarmenu/WidgetMenuItemController.java b/src/com/android/deskclock/actionbarmenu/WidgetMenuItemController.java new file mode 100644 index 000000000..62f295022 --- /dev/null +++ b/src/com/android/deskclock/actionbarmenu/WidgetMenuItemController.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2016 The CyanogenMod 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 com.android.deskclock.actionbarmenu; + +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager.NameNotFoundException; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; + +import com.android.deskclock.R; + +import static android.view.Menu.NONE; + +/** + * {@link MenuItemController} for setting menu. + */ +public final class WidgetMenuItemController implements MenuItemController { + + private static final String LOG_TAG = "DeskClock"; + + private static final String LC_PACKAGE = "org.lineageos.lockclock"; + private static final String LC_ACTIVITY = LC_PACKAGE + ".preference.Preferences"; + private static final ComponentName sWidgetSettingComponentName = new ComponentName + (LC_PACKAGE, LC_ACTIVITY); + + private static final int WIDGET_MENU_RES_ID = R.id.menu_item_widget_settings; + private final Context mContext; + + public WidgetMenuItemController(Context context) { + mContext = context; + } + + @Override + public int getId() { + return WIDGET_MENU_RES_ID; + } + + @Override + public void onCreateOptionsItem(Menu menu) { + menu.add(NONE, WIDGET_MENU_RES_ID, NONE, R.string.menu_item_widget_settings) + .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); + } + + @Override + public void onPrepareOptionsItem(MenuItem item) { + item.setVisible(isPackageInstalled(LC_PACKAGE)); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + Intent wsi = new Intent(); + wsi.setComponent(sWidgetSettingComponentName); + mContext.startActivity(wsi); + return true; + } + + private boolean isPackageInstalled(String pkg) { + if (pkg == null) { + return false; + } + try { + PackageInfo pi = mContext.getPackageManager().getPackageInfo(pkg, 0); + if (!pi.applicationInfo.enabled) { + return false; + } else { + return true; + } + } catch (NameNotFoundException e) { + return false; + } + } +} |