From 1f3d44ff3129c6de53636611425849714482b23c Mon Sep 17 00:00:00 2001 From: Yanuar Harry Date: Thu, 20 Mar 2014 20:53:48 +0700 Subject: [PATCH] CFibers - Implement App circle sidebar [2/2] Add whitelist app to include Add Trigger region control Change-Id: I47862e45b87d65a2b96ff6ecccc8beadba7a9440 Signed-off-by: MURA Stefano [STELIX PippoX3] --- res/values/strings.xml | 14 ++ res/xml/ui_app_circle.xml | 78 +++++++++++ .../fibers/fragments/ui/AppCircleSideBar.java | 129 ++++++++++++++++++ .../fragments/ui/InterfaceSettings.java | 4 +- 4 files changed, 224 insertions(+), 1 deletion(-) create mode 100644 res/xml/ui_app_circle.xml create mode 100644 src/com/carbon/fibers/fragments/ui/AppCircleSideBar.java diff --git a/res/values/strings.xml b/res/values/strings.xml index f4c3f44..bbe1e9e 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -181,6 +181,20 @@ Enabled for %s Enabled + + App launcher + App circle bar + Show circle app launcher after touching right side of screen + Included apps + Apps will show in app circle bar + Trigger region + Trigger width + Adjust the width of the trigger area + Trigger position + Adjust the vertical postion of the trigger area + Trigger height + Adjust the height of the trigger area + Persistence Persistence diff --git a/res/xml/ui_app_circle.xml b/res/xml/ui_app_circle.xml new file mode 100644 index 0000000..a051622 --- /dev/null +++ b/res/xml/ui_app_circle.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/com/carbon/fibers/fragments/ui/AppCircleSideBar.java b/src/com/carbon/fibers/fragments/ui/AppCircleSideBar.java new file mode 100644 index 0000000..961a272 --- /dev/null +++ b/src/com/carbon/fibers/fragments/ui/AppCircleSideBar.java @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2014 The CarbonRom 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.carbon.fibers.fragments.ui; + +import android.os.Bundle; +import android.preference.ListPreference; +import android.preference.Preference; +import android.preference.PreferenceScreen; +import android.provider.Settings; + +import android.text.TextUtils; +import com.carbon.fibers.chameleonos.AppMultiSelectListPreference; +import com.android.internal.util.omni.DeviceUtils; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import com.carbon.fibers.R; +import com.carbon.fibers.chameleonos.SeekBarPreference; +import com.carbon.fibers.preference.SettingsPreferenceFragment; + +public class AppCircleSideBar extends SettingsPreferenceFragment implements + Preference.OnPreferenceChangeListener { + private static final String TAG = "AppCircleSideBar"; + private static final String KEY_TRIGGER_WIDTH = "trigger_width"; + private static final String KEY_TRIGGER_TOP = "trigger_top"; + private static final String KEY_TRIGGER_BOTTOM = "trigger_bottom"; + private static final String PREF_INCLUDE_APP_CIRCLE_BAR_KEY = "app_circle_bar_included_apps"; + private AppMultiSelectListPreference mIncludedAppCircleBar; + private SeekBarPreference mTriggerWidthPref; + private SeekBarPreference mTriggerTopPref; + private SeekBarPreference mTriggerBottomPref; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + addPreferencesFromResource(R.xml.ui_app_circle); + PreferenceScreen prefScreen = getPreferenceScreen(); + + mIncludedAppCircleBar = (AppMultiSelectListPreference) prefScreen.findPreference(PREF_INCLUDE_APP_CIRCLE_BAR_KEY); + Set includedApps = getIncludedApps(); + if (includedApps != null) mIncludedAppCircleBar.setValues(includedApps); + mIncludedAppCircleBar.setOnPreferenceChangeListener(this); + mTriggerWidthPref = (SeekBarPreference) findPreference(KEY_TRIGGER_WIDTH); + mTriggerWidthPref.setValue(Settings.System.getInt(getContentResolver(), + Settings.System.APP_CIRCLE_BAR_TRIGGER_WIDTH, 10)); + mTriggerWidthPref.setOnPreferenceChangeListener(this); + mTriggerTopPref = (SeekBarPreference) findPreference(KEY_TRIGGER_TOP); + mTriggerTopPref.setValue(Settings.System.getInt(getContentResolver(), + Settings.System.APP_CIRCLE_BAR_TRIGGER_TOP, 0)); + mTriggerTopPref.setOnPreferenceChangeListener(this); + mTriggerBottomPref = (SeekBarPreference) findPreference(KEY_TRIGGER_BOTTOM); + mTriggerBottomPref.setValue(Settings.System.getInt(getContentResolver(), + Settings.System.APP_CIRCLE_BAR_TRIGGER_HEIGHT, 100)); + mTriggerBottomPref.setOnPreferenceChangeListener(this); + } + + public boolean onPreferenceChange(Preference preference, Object objValue) { + if (preference == mIncludedAppCircleBar) { + storeIncludedApps((Set) objValue); + return true; + } else if (preference == mTriggerWidthPref) { + int width = ((Integer)objValue).intValue(); + Settings.System.putInt(getContentResolver(), + Settings.System.APP_CIRCLE_BAR_TRIGGER_WIDTH, width); + return true; + } else if (preference == mTriggerTopPref) { + int top = ((Integer)objValue).intValue(); + Settings.System.putInt(getContentResolver(), + Settings.System.APP_CIRCLE_BAR_TRIGGER_TOP, top); + return true; + } else if (preference == mTriggerBottomPref) { + int bottom = ((Integer)objValue).intValue(); + Settings.System.putInt(getContentResolver(), + Settings.System.APP_CIRCLE_BAR_TRIGGER_HEIGHT, bottom); + return true; + } + return false; + } + private Set getIncludedApps() { + String included = Settings.System.getString(getActivity().getContentResolver(), + Settings.System.WHITELIST_APP_CIRCLE_BAR); + if (TextUtils.isEmpty(included)) { + return null; + } + return new HashSet(Arrays.asList(included.split("\\|"))); + } + + private void storeIncludedApps(Set values) { + StringBuilder builder = new StringBuilder(); + String delimiter = ""; + for (String value : values) { + builder.append(delimiter); + builder.append(value); + delimiter = "|"; + } + Settings.System.putString(getActivity().getContentResolver(), + Settings.System.WHITELIST_APP_CIRCLE_BAR, builder.toString()); + } + + @Override + public void onPause() { + super.onPause(); + Settings.System.putInt(getContentResolver(), + Settings.System.APP_CIRCLE_BAR_SHOW_TRIGGER, 0); + } + + @Override + public void onResume() { + super.onResume(); + Settings.System.putInt(getContentResolver(), + Settings.System.APP_CIRCLE_BAR_SHOW_TRIGGER, 1); + } +} diff --git a/src/com/carbon/fibers/fragments/ui/InterfaceSettings.java b/src/com/carbon/fibers/fragments/ui/InterfaceSettings.java index bebff86..97b1612 100644 --- a/src/com/carbon/fibers/fragments/ui/InterfaceSettings.java +++ b/src/com/carbon/fibers/fragments/ui/InterfaceSettings.java @@ -95,6 +95,7 @@ public StatusBarAdapter(FragmentManager fm) { frags[1] = new RecentsPanel(); frags[2] = new BatterySaverSettings(); frags[3] = new ProgressBar(); + frags[4] = new AppCircleSideBar(); } @Override @@ -119,7 +120,8 @@ private String[] getTitles() { getString(R.string.ui_general_category), getString(R.string.ui_recents_category), getString(R.string.battery_saver_title), - getString(R.string.progressbar_title)}; + getString(R.string.progressbar_title), + getString(R.string.category_app_circle_bar_title)}; return titleString; } }