summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Brabham <optedoblivion@cyngn.com>2015-04-24 13:56:00 -0700
committerMichael Bestas <mikeioannina@gmail.com>2016-12-30 18:01:57 +0200
commit65db68f2414e0eb61bae3280dc0b74408dc2fd37 (patch)
tree2bf249a22b68c977893ec56d54409f4b1ecda327
parent2f022d04823ccd10d55778aa7ed19d9c94583191 (diff)
downloadandroid_packages_apps_DeskClock-65db68f2414e0eb61bae3280dc0b74408dc2fd37.tar.gz
android_packages_apps_DeskClock-65db68f2414e0eb61bae3280dc0b74408dc2fd37.tar.bz2
android_packages_apps_DeskClock-65db68f2414e0eb61bae3280dc0b74408dc2fd37.zip
Make new menu entry to link to cLock widget settings.
* slightly modified for N Change-Id: I13ca3156c34eccdd8f60d8585281ae0585aac58e
-rwxr-xr-xres/menu/desk_clock_menu.xml6
-rw-r--r--res/values/cm_strings.xml21
-rw-r--r--src/com/android/deskclock/DeskClock.java4
-rw-r--r--src/com/android/deskclock/actionbarmenu/WidgetMenuItemController.java81
4 files changed, 110 insertions, 2 deletions
diff --git a/res/menu/desk_clock_menu.xml b/res/menu/desk_clock_menu.xml
index e8f903093..9bfebeec2 100755
--- a/res/menu/desk_clock_menu.xml
+++ b/res/menu/desk_clock_menu.xml
@@ -45,8 +45,12 @@
android:icon="@android:drawable/ic_menu_preferences"
android:title="@string/menu_item_settings"/>
<item
+ android:id="@+id/menu_item_widget_settings"
+ android:icon="@android:drawable/ic_menu_preferences"
+ android:title="@string/menu_item_widget_settings"/>
+ <item
android:id="@+id/menu_item_help"
android:icon="@android:drawable/ic_menu_preferences"
android:title="@string/menu_item_help"/>
</group>
-</menu> \ No newline at end of file
+</menu>
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/src/com/android/deskclock/DeskClock.java b/src/com/android/deskclock/DeskClock.java
index f04b8d6e3..ffcf3aca0 100644
--- a/src/com/android/deskclock/DeskClock.java
+++ b/src/com/android/deskclock/DeskClock.java
@@ -43,6 +43,7 @@ import com.android.deskclock.actionbarmenu.ActionBarMenuManager;
import com.android.deskclock.actionbarmenu.MenuItemControllerFactory;
import com.android.deskclock.actionbarmenu.NightModeMenuItemController;
import com.android.deskclock.actionbarmenu.SettingMenuItemController;
+import com.android.deskclock.actionbarmenu.WidgetMenuItemController;
import com.android.deskclock.alarms.AlarmStateManager;
import com.android.deskclock.data.DataModel;
import com.android.deskclock.events.Events;
@@ -199,7 +200,8 @@ public class DeskClock extends BaseActivity
.addMenuItemController(new SettingMenuItemController(this))
.addMenuItemController(new NightModeMenuItemController(this))
.addMenuItemController(MenuItemControllerFactory.getInstance()
- .buildMenuItemControllers(this));
+ .buildMenuItemControllers(this))
+ .addMenuItemController(new WidgetMenuItemController(this));
// Inflate the menu during creation to avoid a double layout pass. Otherwise, the menu
// inflation occurs *after* the initial draw and a second layout pass adds in the menu.
diff --git a/src/com/android/deskclock/actionbarmenu/WidgetMenuItemController.java b/src/com/android/deskclock/actionbarmenu/WidgetMenuItemController.java
new file mode 100644
index 000000000..4e22e7497
--- /dev/null
+++ b/src/com/android/deskclock/actionbarmenu/WidgetMenuItemController.java
@@ -0,0 +1,81 @@
+/*
+ * 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;
+
+/**
+ * {@link MenuItemController} for setting menu.
+ */
+public final class WidgetMenuItemController extends AbstractMenuItemController {
+
+ private static final String LOG_TAG = "DeskClock";
+
+ private static final String LC_PACKAGE = "com.cyanogenmod.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 showMenuItem(Menu menu) {
+ menu.findItem(WIDGET_MENU_RES_ID).setVisible(isPackageInstalled(LC_PACKAGE));
+ }
+
+ @Override
+ public boolean handleMenuItemClick(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;
+ }
+ }
+}