[2/2] OmniGears: Clear All button added in  Recent Panelview

Base: https://gerrit.omnirom.org/#/c/2465/

PS6: setting to change button gravity

Change-Id: Ie0ac94d83a9e450e685837525b8e5c5c7764e5b7
diff --git a/res/values/custom_arrays.xml b/res/values/custom_arrays.xml
index 44c0cd2..1cafba7 100644
--- a/res/values/custom_arrays.xml
+++ b/res/values/custom_arrays.xml
@@ -123,4 +123,18 @@
         <item>9</item>
     </string-array>
 
+    <string-array name="recent_clear_all_button_location_entries" translatable="false">
+        <item>@string/recent_clear_all_button_location_top_left</item>
+        <item>@string/recent_clear_all_button_location_top_right</item>
+        <item>@string/recent_clear_all_button_location_bottom_left</item>
+        <item>@string/recent_clear_all_button_location_bottom_right</item>
+    </string-array>
+
+    <string-array name="recent_clear_all_button_location_values" translatable="false">
+        <item>0</item>
+        <item>1</item>
+        <item>2</item>
+        <item>3</item>
+    </string-array>
+
 </resources>
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index 1ed331b..c9ee678 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -197,6 +197,17 @@
     <string name="keys_action_double">Double tap</string>
     <string name="dialog_no_home_key_title">No home action</string>
     <string name="no_home_key">You have no button assigned to the \"Home\" action! This can make your device unusable!</string>
+
+    <string name="bars_and_menus_category_recent_panel_title" >Recents menu</string>
+
+    <!--  Recents clear all -->
+    <string name="show_recent_clear_all_button_title">Show clear all button</string>
+    <string name="show_recent_clear_all_button_summary">Tick to show or untick to hide the clear all button within the recent applications screen</string>
+    <string name="recent_clear_all_button_location_title">Clear all button position</string>
+    <string name="recent_clear_all_button_location_summary">Choose in which corner the clear all recent apps button is shown</string>
+    <string name="recent_clear_all_button_location_top_left">Top left</string>
+    <string name="recent_clear_all_button_location_top_right">Top right</string>
+    <string name="recent_clear_all_button_location_bottom_left">Bottom left</string>
+    <string name="recent_clear_all_button_location_bottom_right">Bottom right</string>
+
 </resources>
-
-
diff --git a/res/xml/bars_and_menus_settings.xml b/res/xml/bars_and_menus_settings.xml
index af09aa1..0eec521 100644
--- a/res/xml/bars_and_menus_settings.xml
+++ b/res/xml/bars_and_menus_settings.xml
@@ -43,4 +43,23 @@
             android:summary="@string/show_network_speed_summary"
             android:defaultValue="false" />
 
+    <PreferenceCategory
+            android:key="category_recent_panel"
+            android:title="@string/bars_and_menus_category_recent_panel_title"/>
+
+    <CheckBoxPreference
+            android:key="recent_menu_clear_all"
+            android:title="@string/show_recent_clear_all_button_title"
+            android:summary="@string/show_recent_clear_all_button_summary"
+            android:defaultValue="true" />
+
+    <ListPreference
+            android:key="recent_menu_clear_all_location"
+            android:title="@string/recent_clear_all_button_location_title"
+            android:summary="@string/recent_clear_all_button_location_summary"
+            android:entries="@array/recent_clear_all_button_location_entries"
+            android:entryValues="@array/recent_clear_all_button_location_values"
+            android:defaultValue="2"
+            android:dependency="recent_menu_clear_all" />
+
 </PreferenceScreen>
diff --git a/src/org/omnirom/omnigears/BarsAndMenusSettings.java b/src/org/omnirom/omnigears/BarsAndMenusSettings.java
index 8160d44..7fecbe5 100644
--- a/src/org/omnirom/omnigears/BarsAndMenusSettings.java
+++ b/src/org/omnirom/omnigears/BarsAndMenusSettings.java
@@ -53,10 +53,14 @@
     private static final String STATUS_BAR_BRIGHTNESS_CONTROL = "status_bar_brightness_control";
     private static final String STATUS_BAR_NOTIF_COUNT = "status_bar_notif_count";
     private static final String STATUS_BAR_TRAFFIC = "status_bar_traffic";
+    private static final String RECENT_MENU_CLEAR_ALL = "recent_menu_clear_all";
+    private static final String RECENT_MENU_CLEAR_ALL_LOCATION = "recent_menu_clear_all_location";
 
     private CheckBoxPreference mStatusBarBrightnessControl;
     private CheckBoxPreference mStatusBarNotifCount;
     private CheckBoxPreference mStatusBarTraffic;
+    private CheckBoxPreference mRecentClearAll;
+    private ListPreference mRecentClearAllPosition;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -88,6 +92,16 @@
         mStatusBarTraffic.setChecked(Settings.System.getInt(resolver,
             Settings.System.STATUS_BAR_TRAFFIC, 0) == 1);
         mStatusBarTraffic.setOnPreferenceChangeListener(this);
+        mRecentClearAll = (CheckBoxPreference) prefSet.findPreference(RECENT_MENU_CLEAR_ALL);
+        mRecentClearAll.setChecked(Settings.System.getInt(resolver,
+            Settings.System.SHOW_CLEAR_RECENTS_BUTTON, 1) == 1);
+        mRecentClearAll.setOnPreferenceChangeListener(this);
+        mRecentClearAllPosition = (ListPreference) prefSet.findPreference(RECENT_MENU_CLEAR_ALL_LOCATION);
+        String recentClearAllPosition = Settings.System.getString(resolver, Settings.System.CLEAR_RECENTS_BUTTON_LOCATION);
+        if (recentClearAllPosition != null) {
+             mRecentClearAllPosition.setValue(recentClearAllPosition);
+        }
+        mRecentClearAllPosition.setOnPreferenceChangeListener(this);
     }
 
     @Override
@@ -107,6 +121,12 @@
             boolean value = (Boolean) objValue;
             Settings.System.putInt(resolver,
                 Settings.System.STATUS_BAR_TRAFFIC, value ? 1 : 0);
+        } else if (preference == mRecentClearAll) {
+            boolean value = (Boolean) objValue;
+            Settings.System.putInt(resolver, Settings.System.SHOW_CLEAR_RECENTS_BUTTON, value ? 1 : 0);
+        } else if (preference == mRecentClearAllPosition) {
+            String value = (String) objValue;
+            Settings.System.putString(resolver, Settings.System.CLEAR_RECENTS_BUTTON_LOCATION, value);
         } else {
             return false;
         }