Skip to content

Commit

Permalink
Should actually fix the problem with settings now
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorcha committed Mar 18, 2015
1 parent 499c737 commit 13cc692
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {
applicationId packageId
minSdkVersion 14
targetSdkVersion 21
versionCode 5
versionName "2.0.1"
versionCode 6
versionName "2.0.2"
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.view.View;

import com.mikekorcha.mediabuttonoverlay.services.OverlayService;
import com.mikekorcha.mediabuttonoverlay.views.MediaOverlayView;

public class MainActivity extends ActionBarActivity {

Expand All @@ -27,12 +28,43 @@ public class MainActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

// Fix settings from previous version to work with this version, if needed
String player = sharedPrefs.getString("player", "Default");

if(player.equals("Google Play")) {
sharedPrefs.edit().putString("player", "PlayMusic").apply();
}
else if(player.equals("Default Music Player")) {
sharedPrefs.edit().putString("player", "Default").apply();
}

try {
// Will fail if it's actually a string, indicating old version, which drops to the catch
// which will fix it
sharedPrefs.getInt("location", 0);
}
catch(ClassCastException e) {
if(sharedPrefs.getString("location", "Left").equals("Left")) {
sharedPrefs.edit().putInt("location", MediaOverlayView.LEFT).apply();
}
else {
sharedPrefs.edit().putInt("location", MediaOverlayView.RIGHT).apply();
}
}

try {
sharedPrefs.getFloat("opacity", 0.5f);
}
catch(ClassCastException e) {
sharedPrefs.edit().putFloat("opacity", sharedPrefs.getInt("opacity", 0) / 100).apply();
}

setContentView(R.layout.activity_main);

that = this;

sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

getFragmentManager().beginTransaction().replace(R.id.content, new PrefFragment()).commit();

findViewById(R.id.btnStart).setOnClickListener(new View.OnClickListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,37 +59,6 @@ public void onCreate() {

sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);

// Fix settings from previous version to work with this version, if needed
String player = sharedPrefs.getString("player", "Default");

if(player.equals("Google Play")) {
sharedPrefs.edit().putString("player", "PlayMusic").apply();
}
else if(player.equals("Default Music Player")) {
sharedPrefs.edit().putString("player", "Default").apply();
}

try {
// Will fail if it's actually a string, indicating old version, which drops to the catch
// which will fix it
sharedPrefs.getInt("location", 0);
}
catch(ClassCastException e) {
if(sharedPrefs.getString("location", "Left").equals("Left")) {
sharedPrefs.edit().putInt("location", MediaOverlayView.LEFT).apply();
}
else {
sharedPrefs.edit().putInt("location", MediaOverlayView.RIGHT).apply();
}
}

try {
sharedPrefs.getFloat("opacity", 0.5f);
}
catch(ClassCastException e) {
sharedPrefs.edit().putFloat("opacity", sharedPrefs.getInt("opacity", 0) / 100);
}

windowManager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);

vibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
Expand Down

0 comments on commit 13cc692

Please sign in to comment.