switch to preferencefragment

This commit is contained in:
Andrew Dolgov 2015-06-02 11:05:27 +04:00
parent 5e2cfd1b2a
commit 3de302182c
4 changed files with 101 additions and 34 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.fox.ttrss" package="org.fox.ttrss"
android:versionCode="332" android:versionCode="333"
android:versionName="1.106" > android:versionName="1.107" >
<uses-sdk <uses-sdk
android:minSdkVersion="15" android:minSdkVersion="15"

View File

@ -5,6 +5,10 @@ import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.MenuItem;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -12,46 +16,37 @@ import java.util.Locale;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
public class PreferencesActivity extends PreferenceActivity { public class PreferencesActivity extends CommonActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
// we use that before parent onCreate so let's init locally
m_prefs = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext());
setAppTheme(m_prefs);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences); setContentView(R.layout.preferences);
/* if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { getSupportActionBar().setDisplayHomeAsUpEnabled(true);
findPreference("enable_condensed_fonts").setEnabled(false); getSupportActionBar().setHomeButtonEnabled(true);
} */
String version = "?"; android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
int versionCode = -1;
String buildTimestamp = "N/A";
try { ft.replace(R.id.preferences_container, new PreferencesFragment());
PackageInfo packageInfo = getPackageManager(). ft.commit();
getPackageInfo(getPackageName(), 0); }
version = packageInfo.versionName; @Override
versionCode = packageInfo.versionCode; public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
ApplicationInfo appInfo = getPackageManager(). case android.R.id.home:
getApplicationInfo(getPackageName(), 0); onBackPressed();
return true;
ZipFile zf = new ZipFile(appInfo.sourceDir); default:
ZipEntry ze = zf.getEntry("classes.dex"); return super.onOptionsItemSelected(item);
long time = ze.getTime();
buildTimestamp = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss",
Locale.getDefault()).format(time);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} }
findPreference("version").setSummary(getString(R.string.prefs_version, version, versionCode));
findPreference("build_timestamp").setSummary(getString(R.string.prefs_build_timestamp, buildTimestamp));
} }
} }

View File

@ -0,0 +1,64 @@
package org.fox.ttrss;
import android.app.Activity;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
public class PreferencesFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
}
public void onResume() {
super.onResume();
String version = "?";
int versionCode = -1;
String buildTimestamp = "N/A";
try {
Activity activity = getActivity();
PackageInfo packageInfo = activity.getPackageManager().
getPackageInfo(activity.getPackageName(), 0);
version = packageInfo.versionName;
versionCode = packageInfo.versionCode;
ApplicationInfo appInfo = activity.getPackageManager().
getApplicationInfo(activity.getPackageName(), 0);
ZipFile zf = new ZipFile(appInfo.sourceDir);
ZipEntry ze = zf.getEntry("classes.dex");
long time = ze.getTime();
buildTimestamp = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss",
Locale.getDefault()).format(time);
findPreference("version").setSummary(getString(R.string.prefs_version, version, versionCode));
findPreference("build_timestamp").setSummary(getString(R.string.prefs_build_timestamp, buildTimestamp));
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/preferences_container"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>