Android Open Source - Dual-Battery-Widget Widget Settings Container






From Project

Back to project page Dual-Battery-Widget.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions f...

If you think the Android project Dual-Battery-Widget listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2012 Artiom Chilaru (http://flexlabs.org)
 *// w  w w. j  a v  a2  s  .c o m
 * 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 org.flexlabs.widgets.dualbattery.widgetsettings;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import org.flexlabs.widgets.dualbattery.BatteryLevel;
import org.flexlabs.widgets.dualbattery.Constants;

public class WidgetSettingsContainer {
    private int textSize;
    private int textPosition;
    private int batterySelection;
    private int textColorCode;
    private int margin;
    private boolean alwaysShow;
    private boolean showNotDocked;
    private boolean showLabel;
    private boolean showOldStatus;
    private boolean swapBatteries;
    private String theme;

    private static SharedPreferences getPreferences(Context context, int widgetId) {
        SharedPreferences pref = context.getSharedPreferences(Constants.SETTINGS_WIDGET_FILE + widgetId, Context.MODE_PRIVATE);
        int version = pref.getInt(Constants.SETTING_VERSION, 1);
        if (version != Constants.SETTING_VERSION_CURRENT)
            updateWidgetSettings(pref, version);
        return pref;
    }

    public WidgetSettingsContainer(Context context, int widgetId) {
        SharedPreferences pref = getPreferences(context, widgetId);
        alwaysShow = pref.getBoolean(Constants.SETTING_ALWAYS_SHOW_DOCK, Constants.SETTING_ALWAYS_SHOW_DOCK_DEFAULT);
        showNotDocked = pref.getBoolean(Constants.SETTING_SHOW_NOT_DOCKED, Constants.SETTING_SHOW_NOT_DOCKED_DEFAULT);
        showLabel = pref.getBoolean(Constants.SETTING_SHOW_LABEL, Constants.SETTING_SHOW_LABEL_DEFAULT);
        showOldStatus = pref.getBoolean(Constants.SETTING_SHOW_OLD_DOCK, Constants.SETTING_SHOW_OLD_DOCK_DEFAULT);
        swapBatteries = pref.getBoolean(Constants.SETTING_SWAP_BATTERIES, Constants.SETTING_SWAP_BATTERIES_DEFAULT);
        textSize = pref.getInt(Constants.SETTING_TEXT_SIZE, Constants.SETTING_TEXT_SIZE_DEFAULT);
        textPosition = pref.getInt(Constants.SETTING_TEXT_POS, Constants.SETTING_TEXT_POS_DEFAULT);
        batterySelection = pref.getInt(Constants.SETTING_SHOW_SELECTION, Constants.SETTING_SHOW_SELECTION_DEFAULT);
        textColorCode = pref.getInt(Constants.SETTING_TEXT_COLOR, Constants.SETTING_TEXT_COLOR_DEFAULT);
        margin = pref.getInt(Constants.SETTING_MARGIN, Constants.SETTING_MARGIN_DEFAULT);
        theme = pref.getString(Constants.SETTING_THEME, Constants.SETTING_THEME_DEFAULT);
    }

    public static boolean getTempUnits(Context context, int widgetId) {
        SharedPreferences pref = getPreferences(context, widgetId);
        return pref.getInt(Constants.SETTING_TEMP_UNITS, Constants.SETTING_TEMP_UNITS_DEFAULT) == Constants.TEMP_UNIT_CELSIUS;
    }

    public static void setTempUnits(Context context, int widgetId, boolean tempUnitsC) {
        SharedPreferences pref = getPreferences(context, widgetId);
        pref.edit()
            .putInt(Constants.SETTING_TEMP_UNITS, tempUnitsC
                ? Constants.TEMP_UNIT_CELSIUS
                : Constants.TEMP_UNIT_FAHRENHEIT)
            .commit();
    }

    public static boolean getUpgradeSwappedSingle(Context context, int widgetId) {
        SharedPreferences pref = getPreferences(context, widgetId);
        boolean justSwapped = pref.getBoolean(Constants.SETTING_JUST_SWAPPED, Constants.SETTING_JUST_SWAPPED_DEFAULT);
        if (justSwapped) {
            pref.edit()
                .remove(Constants.SETTING_JUST_SWAPPED)
                .commit();
        }
        return justSwapped;
    }

    private static void updateWidgetSettings(SharedPreferences pref, int version) {
        SharedPreferences.Editor editor = pref.edit();
        if (version == 1 && pref.getAll().size() == 0)
            version = Constants.SETTING_VERSION_CURRENT;

        if (version == 1) {
            if (pref.contains(Constants.SETTING_TEXT_SIZE)) {
                int textPosition = Integer.valueOf(pref.getString(Constants.SETTING_TEXT_SIZE, String.valueOf(Constants.SETTING_TEXT_SIZE_DEFAULT)));
                editor.putInt(Constants.SETTING_TEXT_SIZE, textPosition);
            }
            if (pref.contains(Constants.SETTING_TEXT_POS)) {
                int textPosition = Integer.valueOf(pref.getString(Constants.SETTING_TEXT_POS, String.valueOf(Constants.SETTING_TEXT_POS_DEFAULT)));
                editor.putInt(Constants.SETTING_TEXT_POS, textPosition);
            }
            if (pref.contains(Constants.SETTING_SHOW_SELECTION)) {
                int batterySelection = Integer.valueOf(pref.getString(Constants.SETTING_SHOW_SELECTION, String.valueOf(Constants.SETTING_SHOW_SELECTION_DEFAULT)));
                editor.putInt(Constants.SETTING_SHOW_SELECTION, batterySelection);
            }
            if (pref.contains(Constants.SETTING_TEXT_COLOR)) {
                int textColorCode = Integer.valueOf(pref.getString(Constants.SETTING_TEXT_COLOR, String.valueOf(Constants.SETTING_TEXT_COLOR_DEFAULT)));
                editor.putInt(Constants.SETTING_TEXT_COLOR, textColorCode);
            }
            if (pref.contains(Constants.SETTING_MARGIN)) {
                int margin = Integer.valueOf(pref.getString(Constants.SETTING_MARGIN, String.valueOf(Constants.SETTING_MARGIN_DEFAULT)));
                editor.putInt(Constants.SETTING_MARGIN, margin);
            }
            if (BatteryLevel.getCurrent().is_dockFriendly())
                editor.putBoolean(Constants.SETTING_JUST_SWAPPED, true);
            version = 2;
        }

        if (version == 2) {
            if (BatteryLevel.getCurrent().is_dockFriendly())
                editor.putBoolean(Constants.SETTING_JUST_SWAPPED, true);
            version = 3;
        }

        if (version == 3) {
            boolean showLabel = pref.getBoolean(Constants.SETTING_SHOW_LABEL, Constants.SETTING_SHOW_LABEL_DEFAULT);
            if (showLabel && !BatteryLevel.getCurrent().is_dockFriendly())
                editor.remove(Constants.SETTING_SHOW_LABEL);
            version = 4;
        }

        editor.putInt(Constants.SETTING_VERSION, version);
        if (Build.VERSION.SDK_INT < 9)
            editor.commit();
        else
            editor.apply();
    }

    public int getTextSize() {
        return textSize;
    }

    public int getTextPosition() {
        return textPosition;
    }

    public int getBatterySelection() {
        return batterySelection;
    }

    public int getTextColorCode() {
        return textColorCode;
    }

    public int getMargin() {
        return margin;
    }

    public boolean isAlwaysShow() {
        return alwaysShow;
    }

    public boolean isShowNotDocked() {
        return showNotDocked;
    }

    public boolean isShowLabel() {
        return showLabel;
    }

    public boolean isShowOldStatus() {
        return showOldStatus;
    }

    public boolean isSwapBatteries() {
        return swapBatteries;
    }

    public String getTheme() {
        return theme;
    }
}




Java Source Code List

org.achartengine.ChartFactory.java
org.achartengine.GraphicalActivity.java
org.achartengine.GraphicalView.java
org.achartengine.ITouchHandler.java
org.achartengine.TouchHandlerOld.java
org.achartengine.TouchHandler.java
org.achartengine.chart.AbstractChart.java
org.achartengine.chart.BarChart.java
org.achartengine.chart.BubbleChart.java
org.achartengine.chart.ClickableArea.java
org.achartengine.chart.CombinedXYChart.java
org.achartengine.chart.CubicLineChart.java
org.achartengine.chart.DialChart.java
org.achartengine.chart.DoughnutChart.java
org.achartengine.chart.LineChart.java
org.achartengine.chart.PieChart.java
org.achartengine.chart.PieMapper.java
org.achartengine.chart.PieSegment.java
org.achartengine.chart.PointStyle.java
org.achartengine.chart.RangeBarChart.java
org.achartengine.chart.RangeStackedBarChart.java
org.achartengine.chart.RoundChart.java
org.achartengine.chart.ScatterChart.java
org.achartengine.chart.TimeChart.java
org.achartengine.chart.XYChart.java
org.achartengine.model.CategorySeries.java
org.achartengine.model.MultipleCategorySeries.java
org.achartengine.model.Point.java
org.achartengine.model.RangeCategorySeries.java
org.achartengine.model.SeriesSelection.java
org.achartengine.model.TimeSeries.java
org.achartengine.model.XYMultipleSeriesDataset.java
org.achartengine.model.XYSeries.java
org.achartengine.model.XYValueSeries.java
org.achartengine.renderer.BasicStroke.java
org.achartengine.renderer.DefaultRenderer.java
org.achartengine.renderer.DialRenderer.java
org.achartengine.renderer.SimpleSeriesRenderer.java
org.achartengine.renderer.XYMultipleSeriesRenderer.java
org.achartengine.renderer.XYSeriesRenderer.java
org.achartengine.tools.AbstractTool.java
org.achartengine.tools.FitZoom.java
org.achartengine.tools.PanListener.java
org.achartengine.tools.Pan.java
org.achartengine.tools.ZoomEvent.java
org.achartengine.tools.ZoomListener.java
org.achartengine.tools.Zoom.java
org.achartengine.util.IndexXYMap.java
org.achartengine.util.MathHelper.java
org.achartengine.util.XYEntry.java
org.flexlabs.widgets.dualbattery.BatteryApplication.java
org.flexlabs.widgets.dualbattery.BatteryLevel.java
org.flexlabs.widgets.dualbattery.BatteryWidget1x1.java
org.flexlabs.widgets.dualbattery.BatteryWidget2x2.java
org.flexlabs.widgets.dualbattery.BatteryWidget3x4.java
org.flexlabs.widgets.dualbattery.BatteryWidgetUpdater.java
org.flexlabs.widgets.dualbattery.BatteryWidget.java
org.flexlabs.widgets.dualbattery.BillingObserver.java
org.flexlabs.widgets.dualbattery.Constants.java
org.flexlabs.widgets.dualbattery.app.AboutFragment.java
org.flexlabs.widgets.dualbattery.app.BatteryHistoryActivity.java
org.flexlabs.widgets.dualbattery.app.DonateFragment.java
org.flexlabs.widgets.dualbattery.app.FeedbackFragment.java
org.flexlabs.widgets.dualbattery.app.SettingsActivity.java
org.flexlabs.widgets.dualbattery.app.SettingsContainer.java
org.flexlabs.widgets.dualbattery.app.SettingsFragment.java
org.flexlabs.widgets.dualbattery.service.BootUpReceiver.java
org.flexlabs.widgets.dualbattery.service.IntentReceiver.java
org.flexlabs.widgets.dualbattery.service.MonitorService.java
org.flexlabs.widgets.dualbattery.service.NotificationManager.java
org.flexlabs.widgets.dualbattery.storage.BatteryLevelAdapter.java
org.flexlabs.widgets.dualbattery.ui.IntegerListPreference.java
org.flexlabs.widgets.dualbattery.ui.PreferenceListFragment.java
org.flexlabs.widgets.dualbattery.ui.SeekBarPreference.java
org.flexlabs.widgets.dualbattery.widgetsettings.BatteryInfoFragment.java
org.flexlabs.widgets.dualbattery.widgetsettings.PropertiesFragment.java
org.flexlabs.widgets.dualbattery.widgetsettings.WidgetActivity.java
org.flexlabs.widgets.dualbattery.widgetsettings.WidgetSettingsContainer.java