Skip to content

Commit

Permalink
Add theming the preferences activity. Fixes #5
Browse files Browse the repository at this point in the history
- update android studio gradle dependencies
- also get rid of headers in preferences - we're too small to categorize preferences for now
  • Loading branch information
Kaned1as committed Jul 17, 2016
1 parent 2c6713f commit def1f28
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 36 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "com.adonai.manman"
Expand Down
13 changes: 1 addition & 12 deletions app/src/main/java/com/adonai/manman/MainPagerActivity.java
Expand Up @@ -3,18 +3,13 @@
import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
Expand Down Expand Up @@ -54,13 +49,7 @@ public class MainPagerActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// should set theme prior to instantiating compat actionbar etc.
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
final String theme = prefs.getString("app.theme", "light");
switch (theme) {
case "light": setTheme(R.style.Light); break;
case "dark": setTheme(R.style.Dark); break;
case "green": setTheme(R.style.Green); break;
}
Utils.setupTheme(this);

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_pager);
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/adonai/manman/Utils.java
Expand Up @@ -142,4 +142,14 @@ public static String detectEncodingOfArchive(File gzipped) throws IOException {

return detector.getDetectedCharset();
}

public static void setupTheme(Activity activity) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
final String theme = prefs.getString("app.theme", "light");
switch (theme) {
case "light": activity.setTheme(R.style.Light); break;
case "dark": activity.setTheme(R.style.Dark); break;
case "green": activity.setTheme(R.style.Green); break;
}
}
}
Expand Up @@ -2,8 +2,12 @@

import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

import com.adonai.manman.R;
import com.adonai.manman.Utils;

import java.util.List;

Expand All @@ -12,25 +16,29 @@
*
* @author Oleg Chernovskiy
*/
public class PreferencesActivity extends PreferenceActivity {
public class PreferencesActivity extends AppCompatActivity {

private Toolbar mActionBar;

@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(android.R.style.Theme_Holo);
// should set theme prior to instantiating compat actionbar etc.
Utils.setupTheme(this);
super.onCreate(savedInstanceState);
}
setContentView(R.layout.activity_preferences);

@Override
protected boolean isValidFragment(String fragmentName) {
return true;
mActionBar = (Toolbar) findViewById(R.id.app_toolbar);
setSupportActionBar(mActionBar);

getFragmentManager().beginTransaction().replace(R.id.content_frame, new MainPreferences()).commit();
}

/**
* Populate the activity with the top-level headers.
*/
@Override
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.global_prefs_headers, target);
public static class MainPreferences extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.global_prefs);
}
}

}
6 changes: 5 additions & 1 deletion app/src/main/res/layout/activity_main_pager.xml
@@ -1,6 +1,7 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
Expand All @@ -14,6 +15,8 @@
custom:elevation="4dp"
custom:popupTheme="?attr/this_theme"/>

<!-- this frame is replaced when other fragments (e.g. man page view) request focus -->
<!-- so don't mind the "UselessParent" warning -->
<FrameLayout
android:id="@+id/replacer"
android:layout_width="match_parent"
Expand All @@ -22,7 +25,8 @@
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
tools:ignore="UselessParent">

<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/res/layout/activity_preferences.xml
@@ -0,0 +1,23 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.Toolbar
android:id="@+id/app_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="?attr/actionbar_theme"
custom:elevation="4dp"
custom:popupTheme="?attr/this_theme"/>


<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />

</LinearLayout>
9 changes: 0 additions & 9 deletions app/src/main/res/xml/global_prefs_headers.xml

This file was deleted.

2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
classpath 'com.android.tools.build:gradle:2.1.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down

0 comments on commit def1f28

Please sign in to comment.