Skip to content
Browse files

remembers last zoom

  • Loading branch information...
1 parent 5f51f60 commit 357b12ee3a68bfd35c3f91c7b9e59d4b6cace79c @ghk committed Jul 5, 2011
Showing with 58 additions and 1 deletion.
  1. +1 −1 AndroidManifest.xml
  2. +57 −0 src/com/kaulahcintaku/comicshelf/SeriesActivity.java
View
2 AndroidManifest.xml
@@ -8,7 +8,7 @@
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.Light">
<activity android:name=".SeriesActivity"
- android:label="@string/app_name">
+ android:label="@string/app_name" android:configChanges="orientation|keyboard|keyboardHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
View
57 src/com/kaulahcintaku/comicshelf/SeriesActivity.java
@@ -9,27 +9,32 @@
import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
+import android.view.Display;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
+import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.TextView;
public class SeriesActivity extends Activity {
private Item selectedItem;
private CoverFlow coverFlow;
+ private String previousOrientation;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
+ previousOrientation = getOrientationString();
String seriesName = null;
boolean readRecent = false;
@@ -83,13 +88,41 @@ public boolean onOptionsItemSelected(MenuItem item) {
}
return true;
}
+
+ @Override
+ protected void onDestroy() {
+ if(coverFlow != null)
+ saveZoom(coverFlow.getZoom());
+ super.onDestroy();
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ coverFlow.setZoom(loadZoom());
+ }
+
+ @Override
+ public void onConfigurationChanged(Configuration newConfig) {
+ super.onConfigurationChanged(newConfig);
+ String newOrientation = newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE ?
+ "landscape" : "portrait";
+ if(coverFlow != null){
+ if(!newOrientation.equals(previousOrientation)){
+ saveZoom(coverFlow.getZoom(), previousOrientation);
+ coverFlow.setZoom(loadZoom(newOrientation));
+ }
+ }
+ previousOrientation = newOrientation;
+ }
private void initialize(final List<Item> items){
setContentView(R.layout.main);
final ItemAdapter coverImageAdapter = new ItemAdapter(this, items, true);
coverFlow = (CoverFlow) findViewById(R.id.coverflow);
+ coverFlow.setZoom(loadZoom());
coverFlow.setAdapter(coverImageAdapter);
coverFlow.setAnimationDuration(1000);
@@ -145,12 +178,14 @@ private void setSelectedItem(Item item){
}
private void runThisActivityAgain(Bundle data){
+ saveZoom(coverFlow.getZoom());
Intent intent = new Intent(SeriesActivity.this, SeriesActivity.class);
intent.putExtras(data);
startActivityForResult(intent, 0);
}
private void runPerfectViewer(Uri data){
+ saveZoom(coverFlow.getZoom());
try{
Intent intent = new Intent();
intent.setClassName("com.rookiestudio.perfectviewer", "com.rookiestudio.perfectviewer.TViewerMain");
@@ -172,4 +207,26 @@ private void runPerfectViewer(Uri data){
alertDialog.show();
}
}
+
+ private void saveZoom(float zoom, String orientation){
+ getSharedPreferences("default", MODE_PRIVATE).edit().putFloat(orientation+"_zoom", zoom).commit();
+ }
+
+ private void saveZoom(float zoom){
+ saveZoom(zoom, getOrientationString());
+ }
+
+ private float loadZoom(){
+ return loadZoom(getOrientationString());
+ }
+
+ private float loadZoom(String orientation){
+ return getSharedPreferences("default", MODE_PRIVATE).getFloat(orientation+"_zoom", -200.0f);
+ }
+
+ private String getOrientationString(){
+ Display display = getWindowManager().getDefaultDisplay();
+ return display.getWidth() > display.getHeight() ? "landscape" : "portrait";
+ }
+
}

0 comments on commit 357b12e

Please sign in to comment.
Something went wrong with that request. Please try again.