@Override
  public void onClick(View v) {
    SharedPreferences gameSettings = getSharedPreferences(GAME_SETTING_PREFS, 0);
    SharedPreferences.Editor editor = gameSettings.edit();

    if (v.getId() == R.id.playBtn) {
      Intent nextIntent;

      SharedPreferences gameState = getSharedPreferences(GameActivity.GAME_STATE_PREFS, 0);
      final int currLevel = gameState.getInt(GameActivity.STATE_LEVEL, 0);

      nextIntent = new Intent(this, GameActivity.class);
      MediaController.stopLoopingSound();

      // startNext intent
      startActivity(nextIntent);
    } else if (v.getId() == R.id.settings_btn) {
      RelativeLayout settingsWrap = (RelativeLayout) findViewById(R.id.other_settings_buttons_wrap);
      if (View.GONE == settingsWrap.getVisibility()) {
        settingsWrap.setVisibility(View.VISIBLE);
      } else {
        settingsWrap.setVisibility(View.GONE);
      }
    } else if (v.getId() == R.id.toggle_sound) {
      boolean soundEdit = gameSettings.getBoolean(SOUND_PREF, true);
      editor.putBoolean(SOUND_PREF, !soundEdit);
      editor.commit();

      if (soundEdit) {
        Toast.makeText(getApplicationContext(), "Sound is turned off", Toast.LENGTH_SHORT).show();
        MediaController.stopLoopingSound();
      } else {
        Toast.makeText(getApplicationContext(), "Sound is turned on", Toast.LENGTH_SHORT).show();
        MediaController.playSoundClip(this, R.raw.background_intro, true);
      }
    } else if (v.getId() == R.id.toggle_vibration) {
      boolean vibrateEdit = gameSettings.getBoolean(VIBRATE_PREF, true);
      editor.putBoolean(VIBRATE_PREF, !vibrateEdit);

      String vibrateState = (!vibrateEdit) ? "on" : "off";
      Toast.makeText(
              getApplicationContext(), "Vibration is turned " + vibrateState, Toast.LENGTH_SHORT)
          .show();
    } else if (v.getId() == R.id.show_credits) {
      new GameAlertDialogBuilder(this)
          .setTitle("Credits")
          .setMessage(this.getResources().getString(R.string.credits))
          .setPositiveButton(
              android.R.string.no,
              new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                  dialog.cancel();
                }
              })
          .show();
    }
    editor.commit();

    updateColorOfSettingsButtons();
  }
示例#2
1
    @Override
    public boolean onContextItemSelected(MenuItem item) {

      int posn = (int) ((AdapterContextMenuInfo) item.getMenuInfo()).position;
      Codec c = codecs.elementAt(posn);
      if (item.getItemId() == MENU_UP) {
        if (posn == 0) return super.onContextItemSelected(item);
        Codec tmp = codecs.elementAt(posn - 1);
        codecs.set(posn - 1, c);
        codecs.set(posn, tmp);
      } else if (item.getItemId() == MENU_DOWN) {
        if (posn == codecs.size() - 1) return super.onContextItemSelected(item);
        Codec tmp = codecs.elementAt(posn + 1);
        codecs.set(posn + 1, c);
        codecs.set(posn, tmp);
      }
      PreferenceScreen ps = getPreferenceScreen();
      SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(Receiver.mContext);
      String v = "";
      SharedPreferences.Editor e = sp.edit();

      for (Codec d : codecs) v = v + d.number() + " ";
      e.putString(Settings.PREF_CODECS, v);
      e.commit();
      ps.removeAll();
      addPreferences(ps);
      return super.onContextItemSelected(item);
    }
 private void saveUsername(String username) {
   SharedPreferences sharedPreferences =
       getSharedPreferences("TarotAppFeedback", Context.MODE_PRIVATE);
   SharedPreferences.Editor editor = sharedPreferences.edit();
   editor.putString("user", username);
   editor.apply();
 }
示例#4
0
  /**
   * Configure PlayHaven
   *
   * @param context of the application
   * @param token configured in the PlayHaven Dashboard
   * @param secret configured in the PlayHaven Dashboard
   * @param projectId for push notification, optionally configured in PlayHaven Dashboard
   * @throws PlayHavenException if a problem occurs
   * @see <a href="https://dashboard.playhaven.com/">https://dashboard.playhaven.com/</a>
   */
  public static void configure(Context context, String token, String secret, String projectId)
      throws PlayHavenException {
    // Minimal validation
    validateToken(token);
    validateSecret(secret);

    // Setup default configuration values
    SharedPreferences.Editor editor = defaultConfiguration(context);

    // Setup PlayHaven values
    editor.putString(Config.Token.toString(), token);
    editor.putString(Config.Secret.toString(), secret);
    editor.putString(Config.PushProjectId.toString(), projectId);

    // And commit it
    editor.commit();

    /**
     * This will generate a log that looks like this:
     *
     * <pre>D/PlayHaven(  754): PlayHaven initialized: 2.0.0-SNAPSHOT-fe5c52f** 2012-11-21 08:45
     * </pre>
     *
     * Which can then be used to find the actual commit the version was against: <code>
     * git log -n 1 fe5c52f</code>
     */
    i("PlayHaven initialized: %s", Version.BANNER);
    debugConfig(context);
  }
 public void setUserColor(final long userId, final int color) {
   if (userId < 0) return;
   mUserColors.put(userId, color);
   final SharedPreferences.Editor editor = mColorPreferences.edit();
   editor.putInt(String.valueOf(userId), color);
   editor.apply();
 }
示例#6
0
 public void setShouldBootWithSystem(boolean value) {
   String key = this.getClass().getName();
   SharedPreferences settings = getSharedPreferences(key, 0);
   SharedPreferences.Editor editor = settings.edit();
   editor.putBoolean(SETTING_BOOT_WITH_SYSTEM, value);
   editor.commit();
 }
示例#7
0
 private void saveUserInfo() {
   SharedPreferences userData = getSharedPreferences(PREFS_NAME, 0);
   SharedPreferences.Editor editor = userData.edit();
   editor.putString("username", username.getText().toString());
   editor.putString("userType", userType.toString());
   editor.commit();
 }
示例#8
0
 public static void setPrefFastForwardSecs(int secs) {
   Log.d(TAG, "setPrefFastForwardSecs(" + secs + ")");
   SharedPreferences.Editor editor =
       PreferenceManager.getDefaultSharedPreferences(instance.context).edit();
   editor.putInt(PREF_FAST_FORWARD_SECS, secs);
   editor.commit();
 }
 public void setmIsOnlyWifi(int nSet) {
   mIsOnlyWifi = nSet;
   SharedPreferences settings = getSharedPreferences(SettingInfo.NET_SETTING, MODE_PRIVATE);
   SharedPreferences.Editor editor = settings.edit();
   editor.putInt("isOnlyWifi", mIsOnlyWifi);
   editor.commit();
 }
示例#10
0
  void saveUrl(String s) {
    SharedPreferences prefs =
        getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
    ArrayList<String> urls = new ArrayList<String>();
    try {
      urls =
          (ArrayList<String>)
              ObjectSerializer.deserialize(
                  prefs.getString(
                      getString(R.string.preference_file_key),
                      ObjectSerializer.serialize(new ArrayList<String>())));
    } catch (IOException e) {
      e.printStackTrace();
    }
    if (!urls.contains(s)) urls.add(s);

    // save the url list to preferences
    SharedPreferences.Editor editor = prefs.edit();
    try {
      editor.putString(getString(R.string.preference_file_key), ObjectSerializer.serialize(urls));
    } catch (IOException e) {
      e.printStackTrace();
    }
    editor.commit();
  }
  /**
   * Writes Facebook profile information into preferences
   *
   * @param profile Facebook profile
   */
  private void writeProfileToPrefs(@Nullable Profile profile) {
    if (profile != null) {
      String id = profile.getId();
      String name = profile.getName();
      String firstName = profile.getFirstName();
      String lastName = profile.getLastName();
      Uri profileUri = profile.getLinkUri();
      Uri profilePictureUri = profile.getProfilePictureUri(100, 100);

      Resources res = LoginActivity.this.getResources();
      SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
      SharedPreferences.Editor editor = prefs.edit();

      editor.putBoolean(res.getString(R.string.pref_fb_logged_in), true);
      editor.putString(res.getString(R.string.pref_fb_facebook_id), id);
      editor.putString(res.getString(R.string.pref_fb_username), name);
      editor.putString(res.getString(R.string.pref_fb_firstname), firstName);
      editor.putString(res.getString(R.string.pref_fb_lastname), lastName);
      editor.putString(
          res.getString(R.string.pref_fb_email), id + res.getString(R.string.at_weconnect_berlin));
      editor.putString(res.getString(R.string.pref_fb_profile_uri), profileUri.getPath());
      editor.putString(
          res.getString(R.string.pref_fb_profile_picture_uri), profilePictureUri.getPath());
      editor.apply();
    }
  }
  public void toggleService(boolean isChecked) {
    Intent service = new Intent(this, MainService.class);
    spe.putBoolean(CHECKBOX_SERVICE_CHECKED, isChecked);
    while (!spe.commit()) {}
    spe.apply();

    if (isChecked) {
      // Start service
      if (!isMyServiceRunning()) {
        startService(service);
      }
    } else {
      // Stop service
      stopService(service);
    }

    checkBoxVolumeButtonHack.setEnabled(isChecked);

    checkBoxMusicHack.setEnabled(isChecked && checkBoxVolumeButtonHack.isChecked());
    checkBoxVoiceCallHack.setEnabled(isChecked && checkBoxVolumeButtonHack.isChecked());
    checkBoxRingHack.setEnabled(isChecked && checkBoxVolumeButtonHack.isChecked());

    checkBoxToggleSafety.setEnabled(isChecked);
    // seekBarSafetyLevel.setEnabled(checkBoxToggleSafety.isChecked() &&
    // checkBoxToggleSafety.isEnabled());
  }
 public void put(String key, int value) {
   SharedPreferences pref = mContext.getSharedPreferences(PREF_NAME, Activity.MODE_PRIVATE);
   SharedPreferences.Editor editor = pref.edit();
   Log.d(TAG, "preference int put");
   editor.putInt(key, value);
   editor.commit();
 }
示例#14
0
 public void setPassword(String password) {
   _password = password;
   SharedPreferences settings = getSharedPreferences(PREF_NAME, 0);
   SharedPreferences.Editor editor = settings.edit();
   editor.putString(PASSWORD, _password);
   editor.commit();
 }
示例#15
0
 public void setLogin(String login) {
   _login = login;
   SharedPreferences settings = getSharedPreferences(PREF_NAME, 0);
   SharedPreferences.Editor editor = settings.edit();
   editor.putString(LOGIN, _login);
   editor.commit();
 }
示例#16
0
  public void loadPreferences() {
    // Get the app's shared preferences
    // prefsPrivate = PreferenceManager.getDefaultSharedPreferences(this);
    prefsPrivate = getSharedPreferences("preferences", Context.MODE_PRIVATE);
    int pcounter = prefsPrivate.getInt("pcounter", 0);

    // A program counter
    prefsEditor = prefsPrivate.edit();
    prefsEditor.putInt("pcounter", ++pcounter);
    prefsEditor.commit(); // Very important

    // Facebook access
    String access_token = prefsPrivate.getString("access_token", null);
    Long access_expires = prefsPrivate.getLong("access_expires", 0);
    if (access_token != null) {
      mFacebook.setAccessToken(access_token);
    }
    if (access_expires != 0) {
      mFacebook.setAccessExpires(access_expires);
    }

    // App's private prefs
    game.setPlayer(
        new Player(
            prefsPrivate.getInt("userid", 0),
            prefsPrivate.getString("user", "Anonomous"),
            prefsPrivate.getString("pass", ""),
            prefsPrivate.getString("email", "")));

    game.setCash(prefsPrivate.getInt("cash", GameMechanics.DEFAULT_CASH));
    // Start a RegisterActivity
    /*if(pcounter <= 1 || game.getPlayer().getUserId() == 0)
    	showRegisterActivity();
    return;*/
  }
  @Override
  public boolean clearExpired(Date date) {
    boolean clearedAny = false;
    SharedPreferences.Editor prefsWriter = cookiePrefs.edit();

    for (ConcurrentHashMap.Entry<String, Cookie> entry : cookies.entrySet()) {
      String name = entry.getKey();
      Cookie cookie = entry.getValue();
      if (cookie.isExpired(date)) {
        // Clear cookies from local store
        cookies.remove(name);

        // Clear cookies from persistent store
        prefsWriter.remove(COOKIE_NAME_PREFIX + name);

        // We've cleared at least one
        clearedAny = true;
      }
    }

    // Update names in persistent store
    if (clearedAny) {
      prefsWriter.putString(COOKIE_NAME_STORE, TextUtils.join(",", cookies.keySet()));
    }
    prefsWriter.commit();

    return clearedAny;
  }
示例#18
0
 public static void setStayAwake(int gameKey, Activity act, boolean stayAwake) {
   SharedPreferences.Editor editor =
       act.getSharedPreferences(Game.PREFERENCES_FILE, Context.MODE_PRIVATE).edit();
   editor.putBoolean(PREFERENCES_STAY_AWAKE + gameKey, stayAwake);
   ActivityUtil.commitOrApplySharedPreferencesEditor(editor);
   applySleepBehavior(gameKey, act);
 }
示例#19
0
 // ---------------------------------------------------------------------------------------
 public static void GuardarPorcentajeRetencionIva(Context c, String bodega) {
   SharedPreferences prefs =
       c.getSharedPreferences("PorcentajeRetencionIva", Context.MODE_PRIVATE);
   SharedPreferences.Editor editor = prefs.edit();
   editor.putString("PorcentajeRetencionIva", bodega);
   editor.commit();
 }
 public void deleteSharedPReferences() {
   SharedPreferences.Editor editor = sharedPreferences.edit();
   editor.putBoolean("rememberLogin", false);
   editor.remove("username");
   editor.remove("password");
   editor.commit();
 }
示例#21
0
 public static void setPrefRewindSecs(int secs) {
   Log.d(TAG, "setPrefRewindSecs(" + secs + ")");
   SharedPreferences.Editor editor =
       PreferenceManager.getDefaultSharedPreferences(instance.context).edit();
   editor.putInt(PREF_REWIND_SECS, secs);
   editor.commit();
 }
  private void useTheme(final Context context) {
    SharedPreferences preferences =
        context.getSharedPreferences(Theme.PREFS_NAME_THEME_SETTING, Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = preferences.edit();
    editor.putString(Theme.PREFS_KEY_PACKAGE_NAME, entry.getPackageName());
    editor.putInt(Theme.PREFS_KEY_RESOURCE_TYPE, Theme.RESOURCES_FROM_APK);
    editor.putString(Theme.PREFS_KEY_THEME_NAME, entry.getName());
    editor.commit();

    Dialog dialog =
        new AlertDialog.Builder(context)
            .setTitle(R.string.title_dialog_alert)
            .setMessage("重启应用皮肤才能生效,确认要退出应用吗?")
            .setPositiveButton(
                R.string.btn_confirm,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    exitApp(context);
                  }
                })
            .setNegativeButton(
                R.string.btn_cancel,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                  }
                })
            .create();
    dialog.show();
  }
示例#23
0
 @Override
 public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
   prefs = getSharedPreferences("user_prefs", Context.MODE_PRIVATE);
   SharedPreferences.Editor editor = prefs.edit();
   editor.putInt("delaySeconds", newVal);
   editor.commit();
 }
示例#24
0
 private static void saveCodecPrefs(SharedPreferences sp) {
   String v = "";
   for (Codec c : codecs) v = v + c.number() + " ";
   SharedPreferences.Editor e = sp.edit();
   e.putString(Settings.PREF_CODECS, v);
   e.commit();
 }
示例#25
0
  @Override
  public void onReceive(Context context, Intent intent) {

    Log.i("WifiO", "RecvTempDisable");

    LogWO logg = new LogWO(context);
    logg.log("WifiOpti Service disabled for 5m");

    SharedPreferences sett = context.getSharedPreferences("WifiOpti", 2);
    SharedPreferences.Editor settEditor = sett.edit();

    settEditor.putBoolean("WifiOptiServiced", false);
    settEditor.putBoolean("WifiOptiTempDisabled", true);
    settEditor.commit();

    // Turn off service
    Intent serviceIntent = new Intent(context, WifiOptiService.class);
    context.stopService(serviceIntent);

    // Schedule restart
    Intent alarmIntent = new Intent(context, RecvTempResume.class);
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0);

    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(System.currentTimeMillis());
    cal.add(Calendar.MINUTE, 5);

    Log.d("WifiO", " -> " + cal.getTime().toString());

    am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), pendingIntent);
  }
示例#26
0
 public static void setCheckLoginBackground(Context ctx) {
   Calendar calendar = Calendar.getInstance();
   SharedPreferences.Editor editor =
       ctx.getSharedPreferences(GLOBAL_SETTING, Context.MODE_PRIVATE).edit();
   editor.putLong(GLOBAL_SETTING_BACKGROUND, calendar.getTimeInMillis());
   editor.commit();
 }
  public static void app_launched(Context context, int days, int launches) {

    SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFS_NAME, 0);

    // Check if app was already rated
    if (prefs.getBoolean("rated", false)) {
      return;
    }

    SharedPreferences.Editor editor = prefs.edit();

    // Increment launch counter
    long launch_count = prefs.getLong("launch_count", 0) + 1;
    editor.putLong("launch_count", launch_count);

    // Get date of first launch
    Long date_firstLaunch = prefs.getLong("date_firstlaunch", 0);
    if (date_firstLaunch == 0) {
      date_firstLaunch = System.currentTimeMillis();
      editor.putLong("date_firstlaunch", date_firstLaunch);
    }

    // Wait at least n days before opening
    if (launch_count >= launches) {
      if (System.currentTimeMillis() >= date_firstLaunch + (days * 24 * 60 * 60 * 1000)) {
        showRateDialog(context, editor);
      }
    }

    editor.commit();
  }
示例#28
0
  static void setInputStreamDefaultValues(
      Context ctx, String sharedPrefsName, boolean force, InputStreamDefaults defaults) {
    final SharedPreferences prefs;

    prefs = ctx.getSharedPreferences(sharedPrefsName, Context.MODE_PRIVATE);

    final boolean needUpdate = force || !prefs.contains(InputRoverFragment.KEY_ENABLE);

    if (needUpdate) {
      SharedPreferences.Editor e = prefs.edit();
      e.putBoolean(InputRoverFragment.KEY_ENABLE, defaults.enable)
          .putString(InputRoverFragment.KEY_TYPE, defaults.type.name())
          .putString(InputRoverFragment.KEY_FORMAT, defaults.format.name())
          .putString(InputRoverFragment.KEY_RECEIVER_OPTION, defaults.receiverOption)
          .commit();

      StartupShutdownSettingsActivity.setDefaultValue(ctx, sharedPrefsName);
      StationPositionActivity.setDefaultValue(ctx, sharedPrefsName, defaults.positionDefaults);
      StreamFileClientFragment.setDefaultValue(ctx, sharedPrefsName, defaults.fileClientDefaults);
      StreamNtripClientFragment.setDefaultValue(ctx, sharedPrefsName, defaults.ntripClientDefaults);
      StreamTcpClientFragment.setDefaultValue(ctx, sharedPrefsName, defaults.tcpClientDefaults);
      StreamBluetoothFragment.setDefaultValue(ctx, sharedPrefsName, defaults.bluetoothDefaults);
      StreamUsbFragment.setDefaultValue(ctx, sharedPrefsName, defaults.usbDefaults);
    }
  }
 public void clearUserColor(final long userId) {
   if (userId < 0) return;
   mUserColors.remove(userId);
   final SharedPreferences.Editor editor = mColorPreferences.edit();
   editor.remove(Long.toString(userId));
   editor.apply();
 }
示例#30
0
  @Override
  public boolean onPreferenceClick(Preference pref) {
    if (pref.getKey().equals(ABOUT_VERSION)) {
      if (m_clickCounter == -1) {
        Toast.makeText(this, R.string.already_developer, Toast.LENGTH_SHORT).show();
        return true;
      }

      ++m_clickCounter;

      if (m_clickCounter == DEV_STEPS) {
        Toast.makeText(this, R.string.now_developer, Toast.LENGTH_SHORT).show();

        SharedPreferences.Editor p = MultiROMMgrApplication.getPreferences().edit();
        p.putBoolean(DEV_ENABLE, true);
        p.commit();

        addDevOptions();
      } else if (m_clickCounter >= 3) {
        String s = getString(R.string.steps_developer, DEV_STEPS - m_clickCounter);
        Toast.makeText(this, s, Toast.LENGTH_SHORT).show();
      }
      return true;
    } else if (pref.getKey().equals(ABOUT_LICENSES)) {
      final Intent intent = new Intent(Intent.ACTION_VIEW).setData(Uri.parse(SRC_URL));
      startActivity(intent);
      return true;
    }
    return false;
  }