switch to preferencefragment
This commit is contained in:
parent
5e2cfd1b2a
commit
3de302182c
@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.fox.ttrss"
|
||||
android:versionCode="332"
|
||||
android:versionName="1.106" >
|
||||
android:versionCode="333"
|
||||
android:versionName="1.107" >
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="15"
|
||||
|
@ -5,6 +5,10 @@ import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
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.text.SimpleDateFormat;
|
||||
@ -12,46 +16,37 @@ import java.util.Locale;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
public class PreferencesActivity extends PreferenceActivity {
|
||||
public class PreferencesActivity extends CommonActivity {
|
||||
@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);
|
||||
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
setContentView(R.layout.preferences);
|
||||
|
||||
/* if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
|
||||
findPreference("enable_condensed_fonts").setEnabled(false);
|
||||
} */
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setHomeButtonEnabled(true);
|
||||
|
||||
String version = "?";
|
||||
int versionCode = -1;
|
||||
String buildTimestamp = "N/A";
|
||||
android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||
|
||||
try {
|
||||
PackageInfo packageInfo = getPackageManager().
|
||||
getPackageInfo(getPackageName(), 0);
|
||||
|
||||
version = packageInfo.versionName;
|
||||
versionCode = packageInfo.versionCode;
|
||||
|
||||
ApplicationInfo appInfo = getPackageManager().
|
||||
getApplicationInfo(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);
|
||||
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
ft.replace(R.id.preferences_container, new PreferencesFragment());
|
||||
ft.commit();
|
||||
}
|
||||
|
||||
findPreference("version").setSummary(getString(R.string.prefs_version, version, versionCode));
|
||||
findPreference("build_timestamp").setSummary(getString(R.string.prefs_build_timestamp, buildTimestamp));
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
onBackPressed();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
8
org.fox.ttrss/src/main/res/layout/preferences.xml
Normal file
8
org.fox.ttrss/src/main/res/layout/preferences.xml
Normal 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>
|
Loading…
Reference in New Issue
Block a user