Create settings in application

This commit is contained in:
Przemek Grondek 2014-07-18 15:35:44 +02:00
parent 4b61eb675a
commit dee9159a50
13 changed files with 103 additions and 1 deletions

View file

@ -61,7 +61,6 @@
</content>
<orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="support-v4-19.1.0" level="project" />
</component>
</module>

View file

@ -28,6 +28,11 @@
android:name=".EntriesActivity"
android:label="@string/title_activity_entries" >
</activity>
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_setting"
android:icon="@drawable/ic_action_settings">
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />

View file

@ -1,6 +1,7 @@
package info.nerull7.mysqlbrowser;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
@ -35,6 +36,8 @@ public class MainActivity extends Activity {
//TODO Handling menu
int id = item.getItemId();
if (id == R.id.action_settings) {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);

View file

@ -0,0 +1,24 @@
package info.nerull7.mysqlbrowser;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.preference.PreferenceActivity;
/**
* Created by nerull7 on 18.07.14.
*/
public class SettingsActivity extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(android.R.id.content, new SettingsFragment())
.commit();
}
}
}

View file

@ -0,0 +1,36 @@
package info.nerull7.mysqlbrowser;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
/**
* Created by nerull7 on 18.07.14.
*/
public class SettingsFragment extends PreferenceFragment{
public final static String ENTRIES_PAGE_LIMIT = "entries_limit";
Preference mEntriesLimit;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
loadPrefs();
}
private void loadPrefs(){
addPreferencesFromResource(R.xml.settings);
mEntriesLimit = findPreference(ENTRIES_PAGE_LIMIT);
}
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if(preference == mEntriesLimit){
new NumberPickerDialog
}
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -0,0 +1,7 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.nerull7.mysqlbrowser.SettingsActivity"
tools:ignore="MergeRootFrame" />

View file

@ -0,0 +1,11 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="info.nerull7.mysqlbrowser.SettingsFragment">
</RelativeLayout>

View file

@ -15,5 +15,9 @@
<string name="error">Error</string>
<string name="title_activity_table">TableActivity</string>
<string name="title_activity_entries">EntriesActivity</string>
<string name="general_category">General</string>
<string name="entries_limit">Entries per page limit</string>
<string name="entries_summary">20 FIXME entries per page</string>
<string name="title_activity_setting">Settings</string>
</resources>

View file

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:title="@string/general_category">
<Preference
android:key="entries_limit"
android:title="@string/entries_limit"
android:summary="@string/entries_summary"
/>
</PreferenceCategory>
</PreferenceScreen>