From ec2cb356c10acc23238ee685f18022b35764e5d3 Mon Sep 17 00:00:00 2001 From: seven332 Date: Sat, 24 May 2014 17:55:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20AbstractActivity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hippo/ehviewer/ui/AbstractActivity.java | 7 +++ .../ehviewer/ui/AbstractFragmentActivity.java | 43 +++++++++++++++++++ .../ui/AbstractPreferenceActivity.java | 43 +++++++++++++++++++ .../ehviewer/ui/AbstractSlidingActivity.java | 43 +++++++++++++++++++ .../hippo/ehviewer/ui/DownloadActivity.java | 8 ---- .../hippo/ehviewer/ui/FavouriteActivity.java | 3 -- src/com/hippo/ehviewer/ui/MangaActivity.java | 8 ---- .../ehviewer/ui/MangaDetailActivity.java | 14 +----- .../ehviewer/ui/MangaDownloadActivity.java | 8 ---- .../hippo/ehviewer/ui/MangaListActivity.java | 15 +------ .../hippo/ehviewer/ui/SettingsActivity.java | 14 +----- 11 files changed, 139 insertions(+), 67 deletions(-) create mode 100644 src/com/hippo/ehviewer/ui/AbstractFragmentActivity.java create mode 100644 src/com/hippo/ehviewer/ui/AbstractPreferenceActivity.java create mode 100644 src/com/hippo/ehviewer/ui/AbstractSlidingActivity.java diff --git a/src/com/hippo/ehviewer/ui/AbstractActivity.java b/src/com/hippo/ehviewer/ui/AbstractActivity.java index 5aaf1bc6d..7591e53d8 100644 --- a/src/com/hippo/ehviewer/ui/AbstractActivity.java +++ b/src/com/hippo/ehviewer/ui/AbstractActivity.java @@ -32,4 +32,11 @@ public abstract class AbstractActivity extends Activity { setRequestedOrientation(screenOri); } + @Override + protected void onResume() { + super.onResume(); + int screenOri = Config.getScreenOriMode(); + if (screenOri != getRequestedOrientation()) + setRequestedOrientation(screenOri); + } } diff --git a/src/com/hippo/ehviewer/ui/AbstractFragmentActivity.java b/src/com/hippo/ehviewer/ui/AbstractFragmentActivity.java new file mode 100644 index 000000000..bc95ce715 --- /dev/null +++ b/src/com/hippo/ehviewer/ui/AbstractFragmentActivity.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2014 Hippo Seven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hippo.ehviewer.ui; + +import android.os.Bundle; +import android.support.v4.app.FragmentActivity; + +import com.hippo.ehviewer.util.Config; + +public abstract class AbstractFragmentActivity extends FragmentActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + int screenOri = Config.getScreenOriMode(); + if (screenOri != getRequestedOrientation()) + setRequestedOrientation(screenOri); + } + + @Override + protected void onResume() { + super.onResume(); + int screenOri = Config.getScreenOriMode(); + if (screenOri != getRequestedOrientation()) + setRequestedOrientation(screenOri); + } + +} diff --git a/src/com/hippo/ehviewer/ui/AbstractPreferenceActivity.java b/src/com/hippo/ehviewer/ui/AbstractPreferenceActivity.java new file mode 100644 index 000000000..76ec1c1fc --- /dev/null +++ b/src/com/hippo/ehviewer/ui/AbstractPreferenceActivity.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2014 Hippo Seven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hippo.ehviewer.ui; + +import com.hippo.ehviewer.util.Config; + +import android.os.Bundle; +import android.preference.PreferenceActivity; + +public class AbstractPreferenceActivity extends PreferenceActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + int screenOri = Config.getScreenOriMode(); + if (screenOri != getRequestedOrientation()) + setRequestedOrientation(screenOri); + } + + @Override + protected void onResume() { + super.onResume(); + int screenOri = Config.getScreenOriMode(); + if (screenOri != getRequestedOrientation()) + setRequestedOrientation(screenOri); + } + +} diff --git a/src/com/hippo/ehviewer/ui/AbstractSlidingActivity.java b/src/com/hippo/ehviewer/ui/AbstractSlidingActivity.java new file mode 100644 index 000000000..748e9fa27 --- /dev/null +++ b/src/com/hippo/ehviewer/ui/AbstractSlidingActivity.java @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2014 Hippo Seven + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.hippo.ehviewer.ui; + +import android.os.Bundle; + +import com.hippo.ehviewer.util.Config; +import com.jeremyfeinstein.slidingmenu.lib.app.SlidingActivity; + +public class AbstractSlidingActivity extends SlidingActivity { + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + int screenOri = Config.getScreenOriMode(); + if (screenOri != getRequestedOrientation()) + setRequestedOrientation(screenOri); + } + + @Override + protected void onResume() { + super.onResume(); + int screenOri = Config.getScreenOriMode(); + if (screenOri != getRequestedOrientation()) + setRequestedOrientation(screenOri); + } + +} diff --git a/src/com/hippo/ehviewer/ui/DownloadActivity.java b/src/com/hippo/ehviewer/ui/DownloadActivity.java index 591e59e74..e42d6e4d2 100644 --- a/src/com/hippo/ehviewer/ui/DownloadActivity.java +++ b/src/com/hippo/ehviewer/ui/DownloadActivity.java @@ -365,14 +365,6 @@ public class DownloadActivity extends AbstractActivity { super.onConfigurationChanged(newConfig); } - @Override - protected void onResume() { - super.onResume(); - int screenOri = Config.getScreenOriMode(); - if (screenOri != getRequestedOrientation()) - setRequestedOrientation(screenOri); - } - @Override protected void onDestroy() { super.onDestroy(); diff --git a/src/com/hippo/ehviewer/ui/FavouriteActivity.java b/src/com/hippo/ehviewer/ui/FavouriteActivity.java index 291dd2fd7..a304079b1 100644 --- a/src/com/hippo/ehviewer/ui/FavouriteActivity.java +++ b/src/com/hippo/ehviewer/ui/FavouriteActivity.java @@ -187,9 +187,6 @@ public class FavouriteActivity extends AbstractActivity { @Override protected void onResume() { super.onResume(); - int screenOri = Config.getScreenOriMode(); - if (screenOri != getRequestedOrientation()) - setRequestedOrientation(screenOri); if (flAdapter != null) flAdapter.notifyDataSetChanged(); diff --git a/src/com/hippo/ehviewer/ui/MangaActivity.java b/src/com/hippo/ehviewer/ui/MangaActivity.java index bb6147af4..ad63e7bed 100644 --- a/src/com/hippo/ehviewer/ui/MangaActivity.java +++ b/src/com/hippo/ehviewer/ui/MangaActivity.java @@ -262,14 +262,6 @@ public class MangaActivity extends AbstractActivity { super.onConfigurationChanged(newConfig); } - @Override - protected void onResume() { - super.onResume(); - int screenOri = Config.getScreenOriMode(); - if (screenOri != getRequestedOrientation()) - setRequestedOrientation(screenOri); - } - @SuppressLint("NewApi") @Override public void onCreate(Bundle savedInstanceState) { diff --git a/src/com/hippo/ehviewer/ui/MangaDetailActivity.java b/src/com/hippo/ehviewer/ui/MangaDetailActivity.java index cfd0f4a2d..303185b58 100644 --- a/src/com/hippo/ehviewer/ui/MangaDetailActivity.java +++ b/src/com/hippo/ehviewer/ui/MangaDetailActivity.java @@ -50,7 +50,7 @@ import android.widget.EditText; import android.widget.LinearLayout; import android.widget.Toast; -public class MangaDetailActivity extends FragmentActivity +public class MangaDetailActivity extends AbstractFragmentActivity implements ActionBar.TabListener { @SuppressWarnings("unused") @@ -74,14 +74,6 @@ public class MangaDetailActivity extends FragmentActivity super.onConfigurationChanged(newConfig); } - @Override - protected void onResume() { - super.onResume(); - int screenOri = Config.getScreenOriMode(); - if (screenOri != getRequestedOrientation()) - setRequestedOrientation(screenOri); - } - @Override protected void onDestroy() { super.onDestroy(); @@ -149,10 +141,6 @@ public class MangaDetailActivity extends FragmentActivity .setTabListener(this)); } - int screenOri = Config.getScreenOriMode(); - if (screenOri != getRequestedOrientation()) - setRequestedOrientation(screenOri); - // Download service Intent it = new Intent(MangaDetailActivity.this, DownloadService.class); bindService(it, mServiceConn, BIND_AUTO_CREATE); diff --git a/src/com/hippo/ehviewer/ui/MangaDownloadActivity.java b/src/com/hippo/ehviewer/ui/MangaDownloadActivity.java index 9b5543548..2f84a467a 100644 --- a/src/com/hippo/ehviewer/ui/MangaDownloadActivity.java +++ b/src/com/hippo/ehviewer/ui/MangaDownloadActivity.java @@ -117,14 +117,6 @@ public class MangaDownloadActivity extends AbstractActivity { //glrv.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } - @Override - protected void onResume() { - super.onResume(); - int screenOri = Config.getScreenOriMode(); - if (screenOri != getRequestedOrientation()) - setRequestedOrientation(screenOri); - } - @SuppressLint("NewApi") @Override public void onWindowFocusChanged(boolean hasFocus) { diff --git a/src/com/hippo/ehviewer/ui/MangaListActivity.java b/src/com/hippo/ehviewer/ui/MangaListActivity.java index f25e7d80d..fced681e1 100644 --- a/src/com/hippo/ehviewer/ui/MangaListActivity.java +++ b/src/com/hippo/ehviewer/ui/MangaListActivity.java @@ -125,7 +125,7 @@ import android.widget.Toast; * * @author Hippo */ -public class MangaListActivity extends SlidingActivity +public class MangaListActivity extends AbstractSlidingActivity implements View.OnClickListener { private static final String TAG = "MangaListActivity"; @@ -1204,15 +1204,6 @@ public class MangaListActivity extends SlidingActivity } } - @Override - protected void onResume() { - super.onResume(); - int screenOri = Config.getScreenOriMode(); - if (screenOri != getRequestedOrientation()) - setRequestedOrientation(screenOri); - - } - @Override protected void onNewIntent(Intent intent) { setIntent(intent); @@ -1287,10 +1278,6 @@ public class MangaListActivity extends SlidingActivity } }); - int screenOri = Config.getScreenOriMode(); - if (screenOri != getRequestedOrientation()) - setRequestedOrientation(screenOri); - Ui.translucent(this); // Download service diff --git a/src/com/hippo/ehviewer/ui/SettingsActivity.java b/src/com/hippo/ehviewer/ui/SettingsActivity.java index f618654be..031bbfc99 100644 --- a/src/com/hippo/ehviewer/ui/SettingsActivity.java +++ b/src/com/hippo/ehviewer/ui/SettingsActivity.java @@ -63,7 +63,7 @@ import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; -public class SettingsActivity extends PreferenceActivity { +public class SettingsActivity extends AbstractPreferenceActivity { @SuppressWarnings("unused") private static String TAG = "Settings"; @@ -110,22 +110,10 @@ public class SettingsActivity extends PreferenceActivity { adjustPadding(); } - @Override - protected void onResume() { - super.onResume(); - int screenOri = Config.getScreenOriMode(); - if (screenOri != getRequestedOrientation()) - setRequestedOrientation(screenOri); - } - @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - int screenOri = Config.getScreenOriMode(); - if (screenOri != getRequestedOrientation()) - setRequestedOrientation(screenOri); - getActionBar().setDisplayHomeAsUpEnabled(true); mSystemBarConfig = Ui.translucent(this);