Search in sources :

Example 31 with SharedPreferences

use of android.content.SharedPreferences in project jpHolo by teusink.

the class AndroidPreferences method execute.

@Override
public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext) {
    cordova.getThreadPool().execute(new Runnable() {

        @Override
        public void run() {
            try {
                final JSONObject params = args.getJSONObject(0);
                final String preferenceLib = params.getString("preferenceLib");
                final String preferenceName = params.getString("preferenceName");
                final String preferenceValue = params.getString("preferenceValue");
                if (preferenceLib != null && preferenceName != null && preferenceValue != null && !preferenceLib.equals("") && !preferenceName.equals("")) {
                    final SharedPreferences settings = cordova.getActivity().getSharedPreferences(preferenceLib, Context.MODE_PRIVATE);
                    final SharedPreferences.Editor editor = settings.edit();
                    if (action.equals("set") && settings != null && editor != null) {
                        editor.putString(preferenceName, preferenceValue);
                        editor.commit();
                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK));
                    } else if (action.equals("get") && settings != null && editor != null) {
                        final String returnValue = settings.getString(preferenceName, "");
                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, returnValue));
                    } else {
                        Log.e(LOG_PROV, LOG_NAME + "Error: " + PluginResult.Status.INVALID_ACTION);
                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
                    }
                } else {
                    Log.e(LOG_PROV, LOG_NAME + "Error: " + PluginResult.Status.ERROR);
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR));
                }
            } catch (final JSONException e) {
                e.printStackTrace();
                Log.e(LOG_PROV, LOG_NAME + "Error: " + PluginResult.Status.JSON_EXCEPTION);
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
            }
        }
    });
    return true;
}
Also used : JSONObject(org.json.JSONObject) PluginResult(org.apache.cordova.PluginResult) SharedPreferences(android.content.SharedPreferences) JSONException(org.json.JSONException)

Example 32 with SharedPreferences

use of android.content.SharedPreferences in project Shuttle by timusus.

the class ThemeUtils method getThemeType.

/**
     * @param context the context
     * @return the current {@link com.simplecity.amp_library.utils.ThemeUtils.ThemeType}
     */
public static int getThemeType(Context context) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    String theme = sharedPreferences.getString("pref_theme_base", "0");
    if (Integer.valueOf(theme) == 0) {
        return ThemeType.TYPE_SOLID_LIGHT;
    } else if (Integer.valueOf(theme) == 1) {
        return ThemeType.TYPE_SOLID_DARK;
    } else if (Integer.valueOf(theme) == 2) {
        return ThemeType.TYPE_SOLID_BLACK;
    }
    return ThemeType.TYPE_SOLID_LIGHT;
}
Also used : SharedPreferences(android.content.SharedPreferences)

Example 33 with SharedPreferences

use of android.content.SharedPreferences in project Shuttle by timusus.

the class ShuttleUtilsPowerMockTest method testIsOnlineWifiConnected.

@Test
public void testIsOnlineWifiConnected() {
    ShuttleApplication mockApplication = mock(ShuttleApplication.class);
    SharedPreferences mockSharedPreferences = mock(SharedPreferences.class);
    ConnectivityManager mockConnectivityManager = mock(ConnectivityManager.class);
    NetworkInfo mockNetworkInfo = mock(NetworkInfo.class);
    mockStatic(PreferenceManager.class);
    mockStatic(ShuttleApplication.class);
    when(PreferenceManager.getDefaultSharedPreferences(any(Context.class))).thenReturn(mockSharedPreferences);
    when(ShuttleApplication.getInstance()).thenReturn(mockApplication);
    // Mock the connection to Wi-Fi
    when(mockApplication.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(mockConnectivityManager);
    when(mockConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)).thenReturn(mockNetworkInfo);
    when(mockNetworkInfo.isConnectedOrConnecting()).thenReturn(true);
    // Test when we care about Wi-Fi (and it's connected), regardless of user preference
    assertThat(ShuttleUtils.isOnline(true)).isTrue();
    // Test when we don't care about Wi-Fi (but it's connected anyway), regardless of user preference
    assertThat(ShuttleUtils.isOnline(false)).isTrue();
}
Also used : Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 34 with SharedPreferences

use of android.content.SharedPreferences in project Shuttle by timusus.

the class ShuttleUtilsPowerMockTest method testIsOnlineCellularConnected.

@Test
public void testIsOnlineCellularConnected() {
    ShuttleApplication mockApplication = mock(ShuttleApplication.class);
    SharedPreferences mockSharedPreferences = mock(SharedPreferences.class);
    ConnectivityManager mockConnectivityManager = mock(ConnectivityManager.class);
    NetworkInfo mockNetworkInfo = mock(NetworkInfo.class);
    mockStatic(PreferenceManager.class);
    mockStatic(ShuttleApplication.class);
    when(PreferenceManager.getDefaultSharedPreferences(any(Context.class))).thenReturn(mockSharedPreferences);
    when(ShuttleApplication.getInstance()).thenReturn(mockApplication);
    // Mock the connection to cellular data, but not Wi-Fi
    when(mockApplication.getSystemService(Context.CONNECTIVITY_SERVICE)).thenReturn(mockConnectivityManager);
    when(mockConnectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI)).thenReturn(null);
    when(mockConnectivityManager.getActiveNetworkInfo()).thenReturn(mockNetworkInfo);
    when(mockNetworkInfo.isConnectedOrConnecting()).thenReturn(true);
    // Test when we care about Wi-Fi and so does the user (but only cellular is connected)
    when(mockSharedPreferences.getBoolean(eq("pref_download_wifi_only"), anyBoolean())).thenReturn(true);
    assertThat(ShuttleUtils.isOnline(true)).isFalse();
    // Test when we care about Wi-Fi, but the user doesn't (and only cellular is connected)
    when(mockSharedPreferences.getBoolean(eq("pref_download_wifi_only"), anyBoolean())).thenReturn(false);
    assertThat(ShuttleUtils.isOnline(true)).isTrue();
    // Test when we don't care about Wi-Fi, even if the user does (and only cellular is connected)
    when(mockSharedPreferences.getBoolean(eq("pref_download_wifi_only"), anyBoolean())).thenReturn(true);
    assertThat(ShuttleUtils.isOnline(false)).isTrue();
    // Test when we don't care about Wi-Fi and neither does the user (and only cellular is connected)
    when(mockSharedPreferences.getBoolean(eq("pref_download_wifi_only"), anyBoolean())).thenReturn(false);
    assertThat(ShuttleUtils.isOnline(false)).isTrue();
}
Also used : Context(android.content.Context) SharedPreferences(android.content.SharedPreferences) NetworkInfo(android.net.NetworkInfo) ConnectivityManager(android.net.ConnectivityManager) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 35 with SharedPreferences

use of android.content.SharedPreferences in project Shuttle by timusus.

the class DrawableUtils method getColoredAccentDrawable.

/**
     * Takes a drawable and applies the current theme accent color to it
     *
     * @param baseDrawable the drawable to theme
     * @return a themed {@link android.graphics.drawable.Drawable}
     */
public static Drawable getColoredAccentDrawable(Context context, Drawable baseDrawable, boolean canFallBackToWhite, boolean usePrimary) {
    if (baseDrawable == null) {
        return null;
    }
    baseDrawable = baseDrawable.getConstantState().newDrawable();
    int accentColor = ColorUtils.getAccentColor();
    if (accentColor == ColorUtils.getPrimaryColor() && canFallBackToWhite) {
        accentColor = Color.WHITE;
    }
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    if (!canFallBackToWhite && sharedPreferences.getBoolean("pref_theme_white_accent", false)) {
        accentColor = ColorUtils.getAccentColor(false, true);
    }
    if (!canFallBackToWhite && usePrimary && sharedPreferences.getBoolean("pref_theme_white_accent", false)) {
        accentColor = ColorUtils.getPrimaryColor();
    }
    ColorFilter highlightColorFilter = new LightingColorFilter(accentColor, 0);
    baseDrawable.mutate().setColorFilter(highlightColorFilter);
    return baseDrawable;
}
Also used : ColorFilter(android.graphics.ColorFilter) LightingColorFilter(android.graphics.LightingColorFilter) SharedPreferences(android.content.SharedPreferences) LightingColorFilter(android.graphics.LightingColorFilter)

Aggregations

SharedPreferences (android.content.SharedPreferences)1762 Intent (android.content.Intent)221 View (android.view.View)110 Editor (android.content.SharedPreferences.Editor)100 TextView (android.widget.TextView)74 ArrayList (java.util.ArrayList)67 Context (android.content.Context)59 PendingIntent (android.app.PendingIntent)57 File (java.io.File)57 IOException (java.io.IOException)56 Bundle (android.os.Bundle)45 JSONException (org.json.JSONException)41 JSONObject (org.json.JSONObject)41 DialogInterface (android.content.DialogInterface)37 AdapterView (android.widget.AdapterView)34 ImageView (android.widget.ImageView)34 ListView (android.widget.ListView)34 SuppressLint (android.annotation.SuppressLint)33 JSONArray (run.wallet.common.json.JSONArray)33 ComponentName (android.content.ComponentName)31