Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f1d91c1f authored by Martin Brabham's avatar Martin Brabham Committed by Altaf-Mahdi
Browse files

Make new menu entry to link to cLock widget settings.

* slightly modified for N

Change-Id: I13ca3156c34eccdd8f60d8585281ae0585aac58e
parent a537fe8c
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -44,6 +44,10 @@
            android:id="@+id/menu_item_settings"
            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"
+21 −0
Original line number Diff line number Diff line
<?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>
+3 −1
Original line number Diff line number Diff line
@@ -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.
+81 −0
Original line number Diff line number Diff line
/*
 * 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;
        }
    }
}