Android Open Source - jpHolo Android Preferences






From Project

Back to project page jpHolo.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project jpHolo 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

package org.teusink.plugins;
/*from   w  w w . j ava 2  s .  c  o  m*/
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

public class AndroidPreferences extends CordovaPlugin {

  public static final String LOG_PROV = "jpHoloLog";
  public static final String LOG_NAME = "AndroidPreferences Plugin: ";

  @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;
  }
}




Java Source Code List

org.apache.cordova.batterystatus.BatteryListener.java
org.apache.cordova.camera.CameraLauncher.java
org.apache.cordova.camera.ExifHelper.java
org.apache.cordova.camera.FileHelper.java
org.apache.cordova.contacts.ContactAccessorSdk5.java
org.apache.cordova.contacts.ContactAccessor.java
org.apache.cordova.contacts.ContactInfoDTO.java
org.apache.cordova.contacts.ContactManager.java
org.apache.cordova.device.Device.java
org.apache.cordova.devicemotion.AccelListener.java
org.apache.cordova.deviceorientation.CompassListener.java
org.apache.cordova.dialogs.Notification.java
org.apache.cordova.file.ContentFilesystem.java
org.apache.cordova.file.DirectoryManager.java
org.apache.cordova.file.EncodingException.java
org.apache.cordova.file.FileExistsException.java
org.apache.cordova.file.FileHelper.java
org.apache.cordova.file.FileUtils.java
org.apache.cordova.file.Filesystem.java
org.apache.cordova.file.InvalidModificationException.java
org.apache.cordova.file.LocalFilesystemURL.java
org.apache.cordova.file.LocalFilesystem.java
org.apache.cordova.file.NoModificationAllowedException.java
org.apache.cordova.file.TypeMismatchException.java
org.apache.cordova.filetransfer.FileProgressResult.java
org.apache.cordova.filetransfer.FileTransfer.java
org.apache.cordova.filetransfer.FileUploadResult.java
org.apache.cordova.globalization.GlobalizationError.java
org.apache.cordova.globalization.Globalization.java
org.apache.cordova.inappbrowser.InAppBrowserDialog.java
org.apache.cordova.inappbrowser.InAppBrowser.java
org.apache.cordova.inappbrowser.InAppChromeClient.java
org.apache.cordova.media.AudioHandler.java
org.apache.cordova.media.AudioPlayer.java
org.apache.cordova.media.FileHelper.java
org.apache.cordova.mediacapture.Capture.java
org.apache.cordova.mediacapture.FileHelper.java
org.apache.cordova.networkinformation.NetworkManager.java
org.apache.cordova.splashscreen.SplashScreen.java
org.apache.cordova.statusbar.StatusBar.java
org.apache.cordova.vibration.Vibration.java
org.teusink.jpholo.AndroidService.java
org.teusink.jpholo.StartActivityUri.java
org.teusink.jpholo.StartActivity.java
org.teusink.plugins.AndroidPreferences.java
org.teusink.plugins.Appstore.java
org.teusink.plugins.PackageVersion.java
org.teusink.plugins.PreferredScreenSize.java
org.teusink.plugins.Share.java
org.teusink.plugins.Toasts.java