Skip to content

Commit

Permalink
Replaces nested preference screens with preference headers
Browse files Browse the repository at this point in the history
  • Loading branch information
shobhitagarwal1612 committed Jun 26, 2017
1 parent 0d8888a commit d4a393d
Show file tree
Hide file tree
Showing 31 changed files with 949 additions and 525 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.0.0'
}
}
Expand Down
7 changes: 1 addition & 6 deletions collect_app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,9 @@ the specific language governing permissions and limitations under the License.
android:name=".preferences.AboutPreferencesActivity"
android:theme="@style/AppTheme.SettingsTheme"
android:label="@string/app_name" />
<activity
android:name=".preferences.PreferencesActivity"
<activity android:name=".preferences.PreferencesActivity"
android:theme="@style/AppTheme.SettingsTheme"
android:label="@string/app_name" />
<activity
android:name=".preferences.FormMetadataActivity"
android:theme="@style/AppTheme.SettingsTheme"
android:label="@string/form_metadata_title" />
<activity
android:name=".preferences.AdminPreferencesActivity"
android:theme="@style/AppTheme.SettingsTheme"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (C) 2017 Shobhit
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.odk.collect.android.fragments;

import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.view.View;

import org.odk.collect.android.R;
import org.odk.collect.android.preferences.BasePreferenceFragment;

import static android.content.Context.MODE_WORLD_READABLE;
import static org.odk.collect.android.preferences.AdminPreferencesFragment.ADMIN_PREFERENCES;

public class FormEntryAccessPreferences extends BasePreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager prefMgr = getPreferenceManager();
prefMgr.setSharedPreferencesName(ADMIN_PREFERENCES);
prefMgr.setSharedPreferencesMode(MODE_WORLD_READABLE);

addPreferencesFromResource(R.xml.form_entry_access_preferences);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
toolbar.setTitle(R.string.form_entry_setting);
}

@Override
public void onDetach() {
super.onDetach();
if (toolbar != null) {
toolbar.setTitle(R.string.admin_preferences);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2017 Shobhit
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.odk.collect.android.fragments;

import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.view.View;

import org.odk.collect.android.R;
import org.odk.collect.android.preferences.BasePreferenceFragment;

import static android.content.Context.MODE_WORLD_READABLE;
import static org.odk.collect.android.preferences.AdminPreferencesFragment.ADMIN_PREFERENCES;

public class MainMenuAccessPreferences extends BasePreferenceFragment {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager prefMgr = getPreferenceManager();
prefMgr.setSharedPreferencesName(ADMIN_PREFERENCES);
prefMgr.setSharedPreferencesMode(MODE_WORLD_READABLE);

addPreferencesFromResource(R.xml.main_menu_access_preferences);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
toolbar.setTitle(R.string.main_menu_settings);
}

@Override
public void onDetach() {
super.onDetach();
if (toolbar != null) {
toolbar.setTitle(R.string.admin_preferences);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
Expand All @@ -24,7 +23,6 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand All @@ -45,6 +43,7 @@
import org.odk.collect.android.activities.MainMenuActivity;
import org.odk.collect.android.activities.ScannerWithFlashlightActivity;
import org.odk.collect.android.listeners.QRCodeListener;
import org.odk.collect.android.preferences.BasePreferenceFragment;
import org.odk.collect.android.utilities.CompressionUtils;
import org.odk.collect.android.utilities.LocaleHelper;
import org.odk.collect.android.utilities.SharedPreferencesUtils;
Expand All @@ -69,11 +68,7 @@
import static org.odk.collect.android.utilities.QRCodeUtils.saveBitmapToCache;


/**
* Created by shobhit on 6/4/17.
*/

public class ShowQRCodeFragment extends Fragment implements View.OnClickListener, QRCodeListener {
public class ShowQRCodeFragment extends BasePreferenceFragment implements View.OnClickListener, QRCodeListener {

private static final int SELECT_PHOTO = 111;
private boolean[] checkedItems = new boolean[]{true, true};
Expand All @@ -86,8 +81,6 @@ public class ShowQRCodeFragment extends Fragment implements View.OnClickListener
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.show_qrcode_fragment, container, false);
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
toolbar.setTitle(getString(R.string.import_export_settings));
setHasOptionsMenu(true);
setRetainInstance(true);
qrImageView = (ImageView) view.findViewById(R.id.qr_iv);
Expand All @@ -102,6 +95,18 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
return view;
}

@Override
public void onResume() {
super.onResume();
toolbar.setTitle(R.string.import_export_settings);
}

@Override
public void onPause() {
super.onPause();
toolbar.setTitle(R.string.admin_preferences);
}

public void generateCode() {
addPasswordStatusString();
new GenerateQRCode(this).execute();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2017 Shobhit
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.odk.collect.android.fragments;

import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.view.View;

import org.odk.collect.android.R;
import org.odk.collect.android.preferences.BasePreferenceFragment;

import static android.content.Context.MODE_WORLD_READABLE;
import static org.odk.collect.android.preferences.AdminPreferencesFragment.ADMIN_PREFERENCES;

public class UserSettingsAccessPreferences extends BasePreferenceFragment {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
PreferenceManager prefMgr = getPreferenceManager();
prefMgr.setSharedPreferencesName(ADMIN_PREFERENCES);
prefMgr.setSharedPreferencesMode(MODE_WORLD_READABLE);

addPreferencesFromResource(R.xml.user_settings_access_preferences);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
toolbar.setTitle(R.string.user_settings);
}

@Override
public void onDetach() {
super.onDetach();
if (toolbar != null) {
toolbar.setTitle(R.string.admin_preferences);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;

import static org.odk.collect.android.preferences.AdminAndGeneralKeys.ag;

Expand Down Expand Up @@ -34,27 +35,27 @@ public final class AdminKeys {
// server
static final String KEY_CHANGE_ADMIN_PASSWORD = "admin_password";
static final String KEY_IMPORT_SETTINGS = "import_settings";
private static final String KEY_CHANGE_SERVER = "change_server";
private static final String KEY_CHANGE_FORM_METADATA = "change_form_metadata";
public static final String KEY_CHANGE_SERVER = "change_server";
public static final String KEY_CHANGE_FORM_METADATA = "change_form_metadata";

// client
private static final String KEY_CHANGE_FONT_SIZE = "change_font_size";
private static final String KEY_DEFAULT_TO_FINALIZED = "default_to_finalized";
private static final String KEY_HIGH_RESOLUTION = "high_resolution";
private static final String KEY_SHOW_SPLASH_SCREEN = "show_splash_screen";
private static final String KEY_DELETE_AFTER_SEND = "delete_after_send";
private static final String KEY_INSTANCE_FORM_SYNC = "instance_form_sync";
private static final String KEY_APP_LANGUAGE = "app_language";
public static final String KEY_CHANGE_FONT_SIZE = "change_font_size";
public static final String KEY_DEFAULT_TO_FINALIZED = "default_to_finalized";
public static final String KEY_HIGH_RESOLUTION = "high_resolution";
public static final String KEY_SHOW_SPLASH_SCREEN = "show_splash_screen";
public static final String KEY_DELETE_AFTER_SEND = "delete_after_send";
public static final String KEY_INSTANCE_FORM_SYNC = "instance_form_sync";
public static final String KEY_APP_LANGUAGE = "change_app_language";

private static final String KEY_AUTOSEND = "autosend";
public static final String KEY_AUTOSEND = "change_autosend";

private static final String KEY_NAVIGATION = "navigation";
private static final String KEY_CONSTRAINT_BEHAVIOR = "constraint_behavior";
public static final String KEY_NAVIGATION = "change_navigation";
public static final String KEY_CONSTRAINT_BEHAVIOR = "change_constraint_behavior";

private static final String KEY_SHOW_MAP_SDK = "show_map_sdk";
private static final String KEY_SHOW_MAP_BASEMAP = "show_map_basemap";
public static final String KEY_SHOW_MAP_SDK = "show_map_sdk";
public static final String KEY_SHOW_MAP_BASEMAP = "show_map_basemap";

private static final String KEY_ANALYTICS = "analytics";
public static final String KEY_ANALYTICS = "analytics";

public static final String KEY_TIMER_LOG_ENABLED = "timer_log";

Expand Down Expand Up @@ -105,6 +106,33 @@ public final class AdminKeys {
KEY_CHANGE_ADMIN_PASSWORD
);

static Collection<String> serverKeys = Collections.singletonList(
AdminKeys.KEY_CHANGE_SERVER
);

static Collection<String> identityKeys = Arrays.asList(
AdminKeys.KEY_CHANGE_FORM_METADATA,
AdminKeys.KEY_ANALYTICS
);

static Collection<String> formManagementKeys = Arrays.asList(
AdminKeys.KEY_AUTOSEND,
AdminKeys.KEY_DELETE_AFTER_SEND,
AdminKeys.KEY_DEFAULT_TO_FINALIZED,
AdminKeys.KEY_CONSTRAINT_BEHAVIOR,
AdminKeys.KEY_HIGH_RESOLUTION,
AdminKeys.KEY_INSTANCE_FORM_SYNC
);

static Collection<String> userInterfaceKeys = Arrays.asList(
AdminKeys.KEY_APP_LANGUAGE,
AdminKeys.KEY_CHANGE_FONT_SIZE,
AdminKeys.KEY_NAVIGATION,
AdminKeys.KEY_SHOW_SPLASH_SCREEN,
AdminKeys.KEY_SHOW_MAP_BASEMAP,
AdminKeys.KEY_SHOW_MAP_SDK
);

private static Collection<String> allKeys() {
Collection<String> keys = new ArrayList<>();
for (AdminAndGeneralKeys atg : adminToGeneral) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;

import org.odk.collect.android.R;
import org.odk.collect.android.application.Collect;
Expand All @@ -40,7 +43,7 @@
* @author Thomas Smyth, Sassafras Tech Collective ([email protected]; constraint behavior
* option)
*/
public class AdminPreferencesActivity extends AppCompatActivity {
public class AdminPreferencesActivity extends PreferenceActivity {
public static final String ADMIN_PREFERENCES = "admin_prefs";
public static final String TAG = "AdminPreferencesFragment";
private static final int SAVE_PREFS_MENU = Menu.FIRST;
Expand Down Expand Up @@ -75,14 +78,28 @@ public static boolean saveSharedPreferencesToFile(File dst, Context context) {
return res;
}

@Override
protected boolean isValidFragment(String fragmentName) {
return true;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

ViewGroup root = (ViewGroup) findViewById(android.R.id.content);
ViewGroup parent = (ViewGroup) root.getParent();
Toolbar toolbar = (Toolbar) View.inflate(this, R.layout.toolbar, null);
toolbar.setTitle(R.string.admin_preferences);
View shadow = View.inflate(this, R.layout.toolbar_action_bar_shadow, null);

parent.addView(toolbar, 0);
parent.addView(shadow, 1);

if (savedInstanceState == null) {
getFragmentManager()
.beginTransaction()
.replace(android.R.id.content, new AdminPreferencesFragment(), TAG)
.add(android.R.id.content, new AdminPreferencesFragment(), TAG)
.commit();
}
}
Expand Down
Loading

0 comments on commit d4a393d

Please sign in to comment.