com.pixplicity.easyprefs.library.Prefs Java Examples

The following examples show how to use com.pixplicity.easyprefs.library.Prefs. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UpodsApplication.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate() {
    isLoaded = false;
    applicationContext = getApplicationContext();
    YandexMetrica.activate(getApplicationContext(), Config.YANDEX_METRICS_API_KEY);
    YandexMetrica.enableActivityAutoTracking(this);
    FacebookSdk.sdkInitialize(applicationContext);
    LoginMaster.getInstance().init();
    new Prefs.Builder()
            .setContext(this)
            .setMode(ContextWrapper.MODE_PRIVATE)
            .setPrefsName(getPackageName())
            .setUseDefaultSharedPreference(true).build();

    super.onCreate();
}
 
Example #2
Source File: Category.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
/**
 * Call it in application launch to put podcasts categories into the memory
 */
public static void initPodcastsCatrgories() {
    String categoriesJsonStr = Prefs.getString(CATEGORIES_PREF, null);
    if (categoriesJsonStr == null) {
        BackendManager.getInstance().sendRequest(ServerApi.PODCAST_CATEGORIES, new IRequestCallback() {
            @Override
            public void onRequestSuccessed(JSONObject jResponse) {
                try {
                    JSONArray result = jResponse.getJSONArray("result");
                    Prefs.putString(CATEGORIES_PREF, result.toString());
                    Logger.printInfo(CATEGORIES_LOG, "Got " + String.valueOf(result.length()) + " podcasts categories from server");
                } catch (JSONException e) {
                    Logger.printInfo(CATEGORIES_LOG, "Can't get podcasts categories from server");
                    e.printStackTrace();
                }
            }

            @Override
            public void onRequestFailed() {

            }
        });
    }
}
 
Example #3
Source File: SyncMaster.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
@Override
protected Void doInBackground(Void... params) {
    StringBuilder link = new StringBuilder();
    link.append(ServerApi.USER_SYNC);

    try {
        if (task == Task.PULL || !Prefs.contains(GLOBAL_TOKEN)) {
            pullUser(link.toString());
        } else {
            profilePulled = true;
        }

        if (task == Task.PUSH) {
            while (!profilePulled) {
                Thread.sleep(200);
            }
            pushUser(link.toString());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #4
Source File: Settings.java    From faveo-helpdesk-android-app with Open Software License 3.0 6 votes vote down vote up
/**
 *
 * @param inflater for loading the fragment.
 * @param container where the fragment is going to be load.
 * @param savedInstanceState
 * @return after initializing returning the rootview
 * which is having the fragment.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    if (rootView == null) {
        rootView = inflater.inflate(R.layout.fragment_settings, container, false);

        switchCompatCrashReports = (SwitchCompat) rootView.findViewById(R.id.switch_crash_reports);
        switchCompatCrashReports.setChecked(Prefs.getBoolean("CRASH_REPORT", false));
        // switchCompatCrashReports.setOnCheckedChangeListener(this);
        switchCompatCrashReports.setOnClickListener(this);

    }
    ((MainActivity) getActivity()).setActionBarTitle(getString(R.string.settings));
    return rootView;
}
 
Example #5
Source File: FragmentHelp.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_help, container, false);

    if (((IToolbarHolder) getActivity()).getToolbar() != null) {
        ((IToolbarHolder) getActivity()).getToolbar().setVisibility(View.GONE);
    }

    vpHelp = (ViewPager) view.findViewById(R.id.vpHelp);
    indicatorHelp = (CircleIndicator) view.findViewById(R.id.indicatorHelp);
    helpPagesAdapter = new HelpPagesAdapter(getChildFragmentManager());

    initCloseListener();
    helpPagesAdapter.setCloseClickListener(closeClickListener);
    vpHelp.setAdapter(helpPagesAdapter);
    indicatorHelp.setViewPager(vpHelp);
    Prefs.putBoolean(PREF_HELP_SHOWN, true);
    return view;
}
 
Example #6
Source File: FragmentPlayer.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
private void askPhoneStatePermissions() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Prefs.getBoolean(PREF_PHONE_PERM_ASKED, false)) {
        Prefs.putBoolean(PREF_PHONE_PERM_ASKED, true);
        new MaterialDialog.Builder(getActivity())
                .title(R.string.phone_state_permissions)
                .content(R.string.phone_state_description)
                .positiveText(R.string.ok)
                .onAny(new MaterialDialog.SingleButtonCallback() {
                    @TargetApi(Build.VERSION_CODES.M)
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        getActivity().requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE}, CODE_PERMISSIONS_PHONE_STATE);
                    }
                }).build().show();
    }
}
 
Example #7
Source File: ConnectJoinGameFragment.java    From tilt-game-android with MIT License 6 votes vote down vote up
@Override
public void onConnected(Connection connection) {
    // create new Player instance for current user, set as player for GameClient
    Player player = new PlayerImpl(connection);
    player.setPlayerName(Prefs.getString(PrefKeys.PLAYER_NAME, ""));
    GoogleFlipGameApplication.getGameClient().setPlayer(player);

    // navigate to lobby to wait for server to start game
    if (getActivity() != null) {
        Intent intent = new Intent(getActivity(), MultiPlayerGameFlowActivity.class);
        intent.putExtra(IntentKeys.FRAGMENT, Fragments.GAME_FLOW_LOBBY);
        startActivity(intent);

        getActivity().finish();
    }
}
 
Example #8
Source File: LoginMaster.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
public void logout() {
    if (AccessToken.getCurrentAccessToken() != null) {
        LoginManager.getInstance().logOut();
        Logger.printInfo(LOG_TAG, "Loged out from facebook");
    }
    if (Twitter.getSessionManager().getActiveSession() != null) {
        Twitter.getSessionManager().clearActiveSession();
        Twitter.logOut();
        Logger.printInfo(LOG_TAG, "Loged out from twitter");
    }
    if (VKSdk.isLoggedIn()) {
        VKSdk.logout();
        Logger.printInfo(LOG_TAG, "Loged out from vk");
    }
    Prefs.remove(SyncMaster.GLOBAL_TOKEN);
    userProfile = new UserProfile();
}
 
Example #9
Source File: HTTPConnection.java    From faveo-helpdesk-android-app with Open Software License 3.0 6 votes vote down vote up
private String refreshToken() {
    String result = new Authenticate().postAuthenticateUser(Prefs.getString("USERNAME", null), Prefs.getString("PASSWORD", null));
    if (result == null)
        return null;
    try {
        JSONObject jsonObject = new JSONObject(result);
        String token = jsonObject.getString("token");
        Prefs.putString("TOKEN", token);
        // Preference.setToken(token);
        Authenticate.token = token;
        Helpdesk.token = token;
    } catch (JSONException e) {
        e.printStackTrace();
        return null;
    }
    return "success";
}
 
Example #10
Source File: ConnectPlayerNameFragment.java    From tilt-game-android with MIT License 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = createView(R.layout.fragment_player_name, inflater, container);
    ButterKnife.bind(this, view);

    _playerNameInput.requestFocus();

    // prefill previously set name from preferences if available
    if (Prefs.contains(PrefKeys.PLAYER_NAME)) {
        _playerNameInput.setText(Prefs.getString(PrefKeys.PLAYER_NAME, ""));
        _playerNameInput.setSelection(_playerNameInput.getText().length());
    } else {
        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    }

    return view;
}
 
Example #11
Source File: SettingsManager.java    From uPods-android with Apache License 2.0 6 votes vote down vote up
private JSONObject readSettings() {
    try {
        if (Prefs.getString(JS_SETTINGS, null) == null) {
            JSONObject settingsObject = new JSONObject();
            settingsObject.put(JS_START_SCREEN, DEFAULT_START_SCREEN);
            settingsObject.put(JS_NOTIFY_EPISODES, DEFAULT_NOTIFY_EPISODS);
            settingsObject.put(JS_PODCASTS_UPDATE_TIME, DEFAULT_PODCAST_UPDATE_TIME);
            settingsObject.put(JS_STREAM_QUALITY, DEFAULT_STREAM_QUALITY);
            settingsObject.put(JS_TOPS_LANGUAGE, Locale.getDefault().getLanguage());

            Prefs.putString(JS_TOPS_LANGUAGE, Locale.getDefault().getLanguage());
            Prefs.putString(JS_SETTINGS, settingsObject.toString());
        }
        return new JSONObject(Prefs.getString(JS_SETTINGS, null));
    } catch (JSONException e) {
        Logger.printInfo(TAG, "Can't read settings");
        e.printStackTrace();
    }
    return null;
}
 
Example #12
Source File: MainActivity.java    From EasyPrefs with Apache License 2.0 6 votes vote down vote up
@OnClick({R.id.bt_save_text, R.id.bt_save_number, R.id.bt_force_close})
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.bt_save_text:
            String text = mTextET.getText().toString();
            if (!TextUtils.isEmpty(text)) {
                // one liner to save the String.
                Prefs.putString(SAVED_TEXT, text);
                updateText(text);
            } else {
                Toast.makeText(this, "trying to save a text with lenght 0", Toast.LENGTH_SHORT).show();
            }
            break;
        case R.id.bt_save_number:
            double d = Double.parseDouble(mNumberET.getText().toString());
            Prefs.putDouble(SAVED_NUMBER, d);
            updateNumber(d, false);
            break;
        case R.id.bt_force_close:
            finish();
            break;
        default:
            throw new IllegalArgumentException(
                    "Did you add a new button forget to listen to view ID in the onclick?");
    }
}
 
Example #13
Source File: PreferenceManagerImpl.java    From mirror with Apache License 2.0 5 votes vote down vote up
@Override
public void onPlugged(PluginBus bus) {
    super.onPlugged(bus);
    new Prefs.Builder()
            .setContext(mAppManager.getAppContext())
            .setMode(ContextWrapper.MODE_PRIVATE)
            .setPrefsName(mAppManager.getPackageName())
            .setUseDefaultSharedPreference(true)
            .build();
}
 
Example #14
Source File: ScoreboardFragment.java    From tilt-game-android with MIT License 5 votes vote down vote up
private void checkRoundFinished() {
    if (_gameClient.isRoundFinished()) {
        MultiplayerMode multiplayerMode = MultiplayerMode.values()[Prefs.getInt(PrefKeys.MULTIPLAYER_MODE, 0)];

        if (multiplayerMode.equals(MultiplayerMode.SERVER)) {
            _buttons.setVisibility(View.VISIBLE);
            _waitingForPlayersText.setVisibility(View.GONE);
        } else {
            _waitingForPlayersText.setText(R.string.waiting_to_start_round);
        }
    }
}
 
Example #15
Source File: MultiPlayerGameFlowActivity.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_frame_container);
    ButterKnife.bind(this);
    ActivityUtils.keepScreenOn(this);

    _gameClient = GoogleFlipGameApplication.getGameClient();

    _multiplayerMode = MultiplayerMode.values()[Prefs.getInt(PrefKeys.MULTIPLAYER_MODE, 0)];
    if (_multiplayerMode.equals(MultiplayerMode.CLIENT)) {
        _clientService = GoogleFlipGameApplication.getBluetoothClientService();

        _clientDeviceChangedListener = new DeviceChangeListenerAdapter() {
            @Override
            public void onDeviceRemoved(String deviceName, String address) {
                handleConnectionLost();
            }
        };
    }

    _gameClientListener = new GameClientListenerAdapter() {
        @Override
        public void onClientsChanged(List<ClientVO> clients) {
            checkConnectionLost();
        }
    };

    String fragment;
    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        fragment = extras.getString(IntentKeys.FRAGMENT);
    } else {
        fragment = Fragments.GAME_FLOW_SCOREBOARD;
    }

    navigateTo(fragment);
}
 
Example #16
Source File: FloatPrefSeekBarController.java    From tilt-game-android with MIT License 5 votes vote down vote up
public void initValues(float minValue, float maxValue, float defaultValue) {
    _minValue = minValue;
    _maxValue = maxValue;
    _defaultValue = defaultValue;

    if (!Prefs.contains(_prefsKey)) {
        Prefs.putFloat(_prefsKey, defaultValue);
    }

    _seekBar.setProgress(getProgress());

    updateLabel();
}
 
Example #17
Source File: Detail.java    From faveo-helpdesk-android-app with Open Software License 3.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_detail, container, false);
    setUpViews(rootView);
    animation= AnimationUtils.loadAnimation(getActivity(),R.anim.shake_error);
    progressDialog = new ProgressDialog(getContext());
    progressDialog.setMessage(getString(R.string.fetching_detail));
    // progressDialog.show();
    if (InternetReceiver.isConnected()) {
        task = new FetchTicketDetail(Prefs.getString("TICKETid",null));
        task.execute();
    }
    return rootView;
}
 
Example #18
Source File: ConfigurationManagerImpl.java    From mirror with Apache License 2.0 5 votes vote down vote up
@Override
public String getString(String preferenceKey, String defaultValue) {
    try {
        return Prefs.getString(preferenceKey, defaultValue);
    } catch (ClassCastException e) {
        Timber.e(e, "Error getting the value for %s", preferenceKey);
        Prefs.remove(preferenceKey);
        return defaultValue;
    }
}
 
Example #19
Source File: MainActivity.java    From EasyPrefs with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    // get the saved String from the preference by key, and give a default value
    // if Prefs does not contain the key.
    String s = Prefs.getString(SAVED_TEXT, getString(R.string.not_found));
    double d = Prefs.getDouble(SAVED_NUMBER, -1.0);
    updateText(s);
    updateNumber(d, false);
}
 
Example #20
Source File: MyTickets.java    From faveo-helpdesk-android-app with Open Software License 3.0 5 votes vote down vote up
protected String doInBackground(String... urls) {
    if (nextPageURL.equals("null")) {
        return "all done";
    }
    String result = new Helpdesk().nextPageURL(nextPageURL, Prefs.getString("ID", null));
    if (result == null)
        return null;
    // DatabaseHandler databaseHandler = new DatabaseHandler(context);
    // databaseHandler.recreateTable();
    try {
        JSONObject jsonObject = new JSONObject(result);
        nextPageURL = jsonObject.getString("next_page_url");
        String data = jsonObject.getString("data");
        JSONArray jsonArray = new JSONArray(data);
        for (int i = 0; i < jsonArray.length(); i++) {
            TicketOverview ticketOverview = Helper.parseTicketOverview(jsonArray, i);
            if (ticketOverview != null) {
                ticketOverviewList.add(ticketOverview);
                // databaseHandler.addTicketOverview(ticketOverview);
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    //databaseHandler.close();
    return "success";
}
 
Example #21
Source File: ServerLobbyFragment.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void setupUI() {
    _serverService = GoogleFlipGameApplication.getBluetoothServerService();

    _gameServer = GoogleFlipGameApplication.getGameServer();
    _gameServer.stop();
    _gameServer.initBackgroundColors();
    _gameServer.setDebug(true);

    _gameClient.stop();

    Player player = new PlayerImpl(new LoopBackConnection());
    player.setPlayerName(Prefs.getString(PrefKeys.PLAYER_NAME, ""));

    _gameClient.setPlayer(player);
    _gameServer.addPlayer(player);

    _buttons.setVisibility(View.VISIBLE);
    _nextButton.setVisibility(View.GONE);

    _lookingForHostText.setVisibility(View.GONE);

    _serverDeviceChangedListener = new DeviceChangeListenerAdapter() {
        @Override
        public void onDeviceAdded(String deviceName, String address) {
            if (_gameServer.hasRoomForMorePlayers()) {
                _gameServer.addPlayer(new PlayerImpl(new BluetoothConnection(_serverService, address)));
            }
        }

        @Override
        public void onDeviceRemoved(String deviceName, String address) {
            _gameServer.removePlayer(address);
        }
    };
}
 
Example #22
Source File: HomeActivity.java    From tilt-game-android with MIT License 5 votes vote down vote up
@OnClick(R.id.multi_player_button)
protected void onMultiPlayerButtonClick() {
    SoundManager.getInstance().play(R.raw.tap);

    Prefs.putInt(PrefKeys.GAME_TYPE, GameType.MULTI_PLAYER.ordinal());

    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter == null) {
        AlertUtils.showAlert(this, R.string.no_bluetooth_message, R.string.no_bluetooth_title, R.string.btn_ok);
    } else if (!adapter.isEnabled()) {
        startActivityForResult(new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE), ActivityRequestCode.REQUEST_ENABLE_BT);
    } else {
        startMultiplayer();
    }
}
 
Example #23
Source File: FaveoApplication.java    From faveo-helpdesk-android-app with Open Software License 3.0 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    MultiDex.install(this);
    //AndroidNetworking.initialize(getApplicationContext());
    Fabric.with(this, new Crashlytics());
    instance = this;
    new Prefs.Builder()
            .setContext(this)
            .setMode(ContextWrapper.MODE_PRIVATE)
            .setPrefsName(getPackageName())
            .setUseDefaultSharedPreference(true)
            .build();
}
 
Example #24
Source File: Helper.java    From faveo-helpdesk-android-app with Open Software License 3.0 5 votes vote down vote up
/**
     * Tickets Page.
     * @param jsonArray refers to the array of JSON elements.
     * @param i position of the element in array.
     * @return object for ticket overview.
     */
    public static TicketOverview parseTicketOverview(JSONArray jsonArray, int i) {
        try {
            //Date updated_at = null;
            String firstName = jsonArray.getJSONObject(i).getString("first_name");
            String lastName = jsonArray.getJSONObject(i).getString("last_name");
            String username = jsonArray.getJSONObject(i).getString("user_name");
            // String email = jsonArray.getJSONObject(i).getString("email");
            String profilePic = jsonArray.getJSONObject(i).getString("profile_pic");
            String ticketNumber = jsonArray.getJSONObject(i).getString("ticket_number");
            String ID = jsonArray.getJSONObject(i).getString("id");
            String title = jsonArray.getJSONObject(i).getString("title");
            Prefs.putString("ticket_subject",title);
//            String createdAt = jsonArray.getJSONObject(i).getString("created_at");
//            String departmentName = jsonArray.getJSONObject(i).getString("department_name");
//            String priorityName = jsonArray.getJSONObject(i).getString("priotity_name");
//            String slaPlanName = jsonArray.getJSONObject(i).getString("sla_plan_name");
//            String helpTopicName = jsonArray.getJSONObject(i).getString("help_topic_name");
            String ticketStatusName = jsonArray.getJSONObject(i).getString("ticket_status_name");
            String updatedAt = jsonArray.getJSONObject(i).getString("updated_at");
            String dueDate = jsonArray.getJSONObject(i).getString("overdue_date");
            String priorityColor = jsonArray.getJSONObject(i).getString("priority_color");
            String attachment = jsonArray.getJSONObject(i).getString("attachment");
            String clientname;
            if (firstName == null || firstName.equals(""))
                clientname = username;
            else
                clientname = firstName + " " + lastName;
            return new TicketOverview(Integer.parseInt(ID), profilePic,
                    ticketNumber, clientname, title, updatedAt, priorityColor, ticketStatusName, i + "", attachment, dueDate, clientname);
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
 
Example #25
Source File: ConnectPlayerNameFragment.java    From tilt-game-android with MIT License 5 votes vote down vote up
@OnClick(R.id.next_button)
protected void onNextButtonClick() {
    String playerName = _playerNameInput.getText().toString().trim();

    if (!TextUtils.isEmpty(playerName)) {
        // store name in preferences
        Prefs.putString(PrefKeys.PLAYER_NAME, playerName);
        Prefs.putInt(PrefKeys.MULTIPLAYER_PROTOCOL, MultiplayerProtocol.BLUETOOTH.ordinal());

        // go to connection selection
        navigateTo(Fragments.CONNECT_CLIENTSERVER);
    } else {
        Toast.makeText(getActivity(), "Please fill in your name", Toast.LENGTH_SHORT).show();
    }
}
 
Example #26
Source File: WorldController.java    From tilt-game-android with MIT License 5 votes vote down vote up
public WorldController(int width, int height, float scale, float density, Engine engine) {
    _width = width;
    _height = height;
    _scale = scale;
    _density = density;
    _engine = engine;

    // set physics value from preferences if they have been changed
    BALL_FIX_DEF.density = Prefs.getFloat(PrefKeys.BALL_DENSITY, Physics.BALL_DENSITY);
    _radToGravity = _scale * (float) (Prefs.getFloat(PrefKeys.GRAVITY_FACTOR, Physics.GRAVITY_FACTOR) / Math.PI);
    OBSTACLE_FIX_DEF.restitution = Prefs.getFloat(PrefKeys.WALL_ELASTICITY, Physics.WALL_ELASTICITY);
    _gravityCorrection = Vector2Pool.obtain(Prefs.getFloat(PrefKeys.CALIBRATION_X, 0), Prefs.getFloat(PrefKeys.CALIBRATION_Y, 0));
}
 
Example #27
Source File: CalibrationActivity.java    From tilt-game-android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_calibration);
    ButterKnife.bind(this);
    ScreenUtil.setFullScreen(getWindow().getDecorView());

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        _fromActivity = extras.getString(IntentKeys.FROM);
    }

    _orientationProvider = GoogleFlipGameApplication.getOrientationProvider(this);
    if (_orientationProvider != null) {
        try {
            _orientationProvider.start();
        } catch (Exception e) {
            //
            AlertUtils.showAlert(this, R.string.no_sensor_found_message, R.string.no_sensor_found_title, R.string.btn_ok,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Prefs.putFloat(PrefKeys.CALIBRATION_X, 0);
                            Prefs.putFloat(PrefKeys.CALIBRATION_Y, 0);
                            startActivity(new Intent(CalibrationActivity.this, HomeActivity.class));
                        }
                    });
        }
    }

    _radToGravity = (float) (Prefs.getFloat(PrefKeys.GRAVITY_FACTOR, Physics.GRAVITY_FACTOR) / Math.PI);
}
 
Example #28
Source File: CalibrationActivity.java    From tilt-game-android with MIT License 5 votes vote down vote up
private void calculateAverageGravity() {
    Vector2 gravity = Vector2Pool.obtain();

    for (int i = 10; i < _gravityPoints.size(); i++) {
        gravity.add(_gravityPoints.get(i));
    }
    gravity.mul(-1.0f / _gravityPoints.size());

    Prefs.putFloat(PrefKeys.CALIBRATION_X, gravity.x);
    Prefs.putFloat(PrefKeys.CALIBRATION_Y, gravity.y);
}
 
Example #29
Source File: ConnectClientServerFragment.java    From tilt-game-android with MIT License 5 votes vote down vote up
@OnClick(R.id.btn_start_new_game)
protected void onStartNewGameButtonClick() {
    Prefs.putInt(PrefKeys.MULTIPLAYER_MODE, MultiplayerMode.SERVER.ordinal());

    Intent intent = new Intent(getActivity(), MultiPlayerGameFlowActivity.class);
    intent.putExtra(IntentKeys.FRAGMENT, Fragments.GAME_FLOW_LOBBY);
    startActivity(intent);
}
 
Example #30
Source File: HomeActivity.java    From tilt-game-android with MIT License 5 votes vote down vote up
@OnClick(R.id.single_player_button)
protected void onSinglePlayerButtonClick() {
    SoundManager.getInstance().play(R.raw.tap);

    GoogleFlipGameApplication.getOrientationProvider(this).start();
    GoogleFlipGameApplication.getUserModel().selectNextLockedLevel();

    Prefs.putInt(PrefKeys.GAME_TYPE, GameType.SINGLE_PLAYER.ordinal());

    Intent intent = new Intent(this, SinglePlayerGameFlowActivity.class);
    intent.putExtra(IntentKeys.FRAGMENT, Fragments.GAME_FLOW_SELECT_LEVEL);
    startActivity(intent);

    overridePendingTransition(R.anim.slide_up_in, R.anim.slide_up_out);
}