Preference acitivty

This commit is contained in:
danijoo
2015-12-31 16:43:48 +01:00
parent e27dc19b26
commit 209810bca5
12 changed files with 180 additions and 12 deletions

View File

@@ -1,4 +1,6 @@
apply plugin: 'com.android.application'
// This does not break the build when Android Studio is missing the JRebel for Android plugin.
apply plugin: 'com.zeroturnaround.jrebel.android'
apply plugin: 'com.neenbedankt.android-apt'
android {

View File

@@ -14,6 +14,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".PreferenceActivity"
android:parentActivityName=".MainActivity"/>
</application>
</manifest>

View File

@@ -1,11 +1,11 @@
package net.headlezz.notificationlogger;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.Toast;
import butterknife.Bind;
import butterknife.ButterKnife;
@@ -22,14 +22,15 @@ public class MainActivity extends AppCompatActivity implements Toolbar.OnMenuIte
ButterKnife.bind(this);
mToolbar.inflateMenu(R.menu.main_activity);
mToolbar.setTitle(getString(R.string.app_name));
mToolbar.setOnMenuItemClickListener(this);
}
@Override
public boolean onMenuItemClick(MenuItem item) {
if(item.getItemId() == R.id.menu_settings) {
Toast.makeText(this, "Not implemented", Toast.LENGTH_SHORT).show();
return true;
Intent intent = new Intent(this, PreferenceActivity.class);
startActivity(intent);
}
return false;
}

View File

@@ -0,0 +1,50 @@
package net.headlezz.notificationlogger;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import com.mikepenz.aboutlibraries.LibsBuilder;
import com.mikepenz.aboutlibraries.ui.LibsSupportFragment;
import butterknife.Bind;
import butterknife.ButterKnife;
public class PreferenceActivity extends AppCompatActivity implements PreferenceFragment.PreferenceCallbacks {
@Bind(R.id.toolbar)
Toolbar mToolbar;
@SuppressWarnings("ConstantConditions")
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.preference_activity);
ButterKnife.bind(this);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(R.string.title_settings);
if(getSupportFragmentManager().findFragmentById(R.id.fragment_holder) == null) {
PreferenceFragment pf = new PreferenceFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_holder, pf)
.commit();
}
}
public void showAboutScreen() {
// TODO add other libraries
LibsSupportFragment aboutFrag = new LibsBuilder()
.withAboutAppName(getString(R.string.app_name))
.withAboutIconShown(true)
.withAboutVersionShown(true)
.withAboutVersionShownCode(true)
.supportFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_holder, aboutFrag)
.addToBackStack("about")
.commit();
}
}

View File

@@ -0,0 +1,46 @@
package net.headlezz.notificationlogger;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceFragmentCompat;
public class PreferenceFragment extends PreferenceFragmentCompat implements Preference.OnPreferenceClickListener {
private PreferenceCallbacks mCallbacks;
final String PREF_ABOUT = "pref_about";
interface PreferenceCallbacks {
void showAboutScreen();
}
@Override
public void onCreatePreferences(Bundle bundle, String s) {
addPreferencesFromResource(R.xml.preferences);
findPreference(PREF_ABOUT).setOnPreferenceClickListener(this);
}
@Override
public boolean onPreferenceClick(Preference preference) {
if(preference.getKey().equals(PREF_ABOUT)) {
mCallbacks.showAboutScreen();
return true;
}
return false;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
mCallbacks = (PreferenceCallbacks) activity;
}
@Override
public void onDetach() {
super.onDetach();
mCallbacks = null;
}
}

View File

@@ -1,15 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:background="?attr/colorPrimary"
android:id="@+id/toolbar"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
<include layout="@layout/toolbar" />
</FrameLayout>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar" />
<FrameLayout
android:id="@+id/fragment_holder"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:elevation="?attr/elevation"
android:background="?attr/colorPrimary"
android:id="@+id/toolbar"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />

View File

@@ -1,4 +1,16 @@
<resources>
<string name="app_name">Notification Logger</string>
<string name="menu_item_settings">Settings</string>
<string name="title_settings">Settings</string>
<string name="pref_category_notification_settings">Notification Settings</string>
<string name="pref_category_support">Support</string>
<string name="pref_logging_enabled_title">Notification Logging</string>
<string name="pref_logging_enabled_summary">Enable/Disable notification logging</string>
<string name="pref_blacklist_title">Blacklist</string>
<string name="pref_blacklist_summary">Exclude apps from being logged</string>
<string name="pref_clear_database_title">Clear database</string>
<string name="pref_clear_database_summary">Remove all logged notifications</string>
<string name="pref_export_title">Export to sdcard</string>
<string name="pref_about_title">About</string>
</resources>

View File

@@ -4,6 +4,7 @@
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
</style>
</resources>

View File

@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="screen_notification_settings"
android:title="@string/pref_category_notification_settings">
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="pref_logging_enabled"
android:summary="@string/pref_logging_enabled_summary"
android:title="@string/pref_logging_enabled_title" />
<Preference
android:key="pref_blacklist"
android:summary="@string/pref_blacklist_summary"
android:title="@string/pref_blacklist_title" />
<Preference
android:key="pref_clear_database"
android:summary="@string/pref_clear_database_summary"
android:title="@string/pref_clear_database_title" />
<Preference
android:key="pref_export"
android:title="@string/pref_export_title" />
</PreferenceCategory>
<PreferenceCategory
android:key="screen_support"
android:title="@string/pref_category_support">
<Preference
android:key="pref_about"
android:title="@string/pref_about_title" />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -3,9 +3,14 @@
buildscript {
repositories {
jcenter()
maven {
url 'https://repos.zeroturnaround.com/nexus/content/repositories/zt-public-releases'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.0.0-alpha3'
// This does not break the build when Android Studio is missing the JRebel for Android plugin.
classpath 'com.zeroturnaround.jrebel.android:jr-android-gradle:1.0.+'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.6'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files