Skip to content

Commit

Permalink
Merge pull request getodk#2237 from grzesiek2010/COLLECT-2230
Browse files Browse the repository at this point in the history
Fixed RadioButtons and CheckBoxes in Dark Theme.
  • Loading branch information
lognaturel authored May 30, 2018
2 parents 818d4fb + 0aefc04 commit db0e7f5
Show file tree
Hide file tree
Showing 18 changed files with 198 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import org.odk.collect.android.R;
Expand Down Expand Up @@ -44,18 +43,9 @@ public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
// inflates toolbar in the preference fragments
public void initToolbar(PreferenceScreen preferenceScreen, View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {

if (getActivity() instanceof PreferencesActivity) {
root = (LinearLayout) ((ViewGroup) view.findViewById(android.R.id.list).getRootView()).getChildAt(0);
toolbar = root.findViewById(R.id.toolbar);

} else {
root = (LinearLayout) view.findViewById(android.R.id.list).getParent().getParent();
toolbar = (Toolbar) LayoutInflater.from(getActivity()).inflate(R.layout.toolbar_without_progressbar, root, false);

inflateToolbar(preferenceScreen.getTitle());
}

root = (LinearLayout) view.findViewById(android.R.id.list).getParent().getParent();
toolbar = (Toolbar) LayoutInflater.from(getActivity()).inflate(R.layout.toolbar_without_progressbar, root, false);
inflateToolbar(preferenceScreen.getTitle());
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
root = (LinearLayout) view.findViewById(android.R.id.list).getParent();
toolbar = (Toolbar) LayoutInflater.from(getActivity()).inflate(R.layout.toolbar_without_progressbar, root, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import static org.odk.collect.android.preferences.PreferencesActivity.INTENT_KEY_ADMIN_MODE;


class DisabledPreferencesRemover {

private PreferencesActivity pa;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* Copyright 2018 Nafundi
*
* 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.preferences;

import android.app.Fragment;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceScreen;
import android.support.annotation.Nullable;
import android.view.View;

import org.odk.collect.android.R;

import java.util.Collection;

import static org.odk.collect.android.preferences.PreferencesActivity.INTENT_KEY_ADMIN_MODE;

public class GeneralPreferencesFragment extends BasePreferenceFragment implements Preference.OnPreferenceClickListener {

public static GeneralPreferencesFragment newInstance(boolean adminMode) {
Bundle bundle = new Bundle();
bundle.putBoolean(INTENT_KEY_ADMIN_MODE, adminMode);

GeneralPreferencesFragment generalPreferencesFragment = new GeneralPreferencesFragment();
generalPreferencesFragment.setArguments(bundle);
return generalPreferencesFragment;
}

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

addPreferencesFromResource(R.xml.general_preferences);

findPreference("protocol").setOnPreferenceClickListener(this);
findPreference("user_interface").setOnPreferenceClickListener(this);
findPreference("form_management").setOnPreferenceClickListener(this);
findPreference("user_and_device_identity").setOnPreferenceClickListener(this);

if (!getArguments().getBoolean(INTENT_KEY_ADMIN_MODE)) {
setPreferencesVisibility();
}
}

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

@Override
public boolean onPreferenceClick(Preference preference) {
Fragment fragment = null;
switch (preference.getKey()) {
case "protocol":
fragment = new ServerPreferences();
break;
case "user_interface":
fragment = new UserInterfacePreferences();
break;
case "form_management":
fragment = new FormManagementPreferences();
break;
case "user_and_device_identity":
fragment = new IdentityPreferences();
break;
}

if (fragment != null) {
getActivity()
.getFragmentManager()
.beginTransaction()
.replace(android.R.id.content, fragment)
.addToBackStack(null)
.commit();
}

return true;
}

private void setPreferencesVisibility() {
PreferenceScreen preferenceScreen = getPreferenceScreen();
if (!hasAtleastOneSettingEnabled(AdminKeys.serverKeys)) {
preferenceScreen.removePreference(findPreference("protocol"));
}

if (!hasAtleastOneSettingEnabled(AdminKeys.userInterfaceKeys)) {
preferenceScreen.removePreference(findPreference("user_interface"));
}

if (!hasAtleastOneSettingEnabled(AdminKeys.formManagementKeys)) {
preferenceScreen.removePreference(findPreference("form_management"));
}

if (!hasAtleastOneSettingEnabled(AdminKeys.identityKeys)) {
preferenceScreen.removePreference(findPreference("user_and_device_identity"));
}
}

private boolean hasAtleastOneSettingEnabled(Collection<String> keys) {
AdminSharedPreferences adminSharedPreferences = AdminSharedPreferences.getInstance();
for (String key : keys) {
boolean value = (boolean) adminSharedPreferences.get(key);
if (value) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.identity_preferences);

findPreference("form_metadata").setOnPreferenceClickListener(preference -> {
getActivity().getFragmentManager().beginTransaction()
.replace(android.R.id.content, new FormMetadataFragment())
.addToBackStack(null)
.commit();
return true;
});

initAnalyticsPref();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,124 +1,50 @@
/*
* Copyright (C) 2017 Shobhit
* Copyright 2018 Nafundi
*
* 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
* 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.
* 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.preferences;

import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.ViewGroup;

import org.odk.collect.android.R;
import org.odk.collect.android.activities.CollectAbstractActivity;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.utilities.ThemeUtils;

import java.util.Collection;
import java.util.List;
public class PreferencesActivity extends CollectAbstractActivity {

/**
* Handles general preferences.
*/
public class PreferencesActivity extends PreferenceActivity {
public static final String TAG = "GeneralPreferencesFragment";
public static final String INTENT_KEY_ADMIN_MODE = "adminMode";

private AdminSharedPreferences sharedPreferences;

@Override
public void onBuildHeaders(List<Header> target) {
super.onBuildHeaders(target);

sharedPreferences = AdminSharedPreferences.getInstance();

final boolean adminMode = getIntent().getBooleanExtra(INTENT_KEY_ADMIN_MODE, false);

if (adminMode) {
loadHeadersFromResource(R.xml.general_preference_headers, target);
} else {

if (hasAtleastOneSettingEnabled(AdminKeys.serverKeys)) {
loadHeadersFromResource(R.xml.server_preference_headers, target);
}

if (hasAtleastOneSettingEnabled(AdminKeys.userInterfaceKeys)) {
loadHeadersFromResource(R.xml.user_interface_preference_headers, target);
}

if (hasAtleastOneSettingEnabled(AdminKeys.formManagementKeys)) {
loadHeadersFromResource(R.xml.form_management_preference_headers, target);
}

if (hasAtleastOneSettingEnabled(AdminKeys.identityKeys)) {
loadHeadersFromResource(R.xml.user_device_identity_preference_header, target);
}
}
}

@Override
public void onHeaderClick(Header header, int position) {
final boolean adminMode = getIntent().getBooleanExtra(INTENT_KEY_ADMIN_MODE, false);

if (adminMode) {
Bundle bundle = new Bundle();
bundle.putBoolean(INTENT_KEY_ADMIN_MODE, true);
header.fragmentArguments = bundle;
}

super.onHeaderClick(header, position);
}

private boolean hasAtleastOneSettingEnabled(Collection<String> keys) {
for (String key : keys) {
boolean value = (boolean) sharedPreferences.get(key);
if (value) {
return true;
}
}
return false;
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(new ThemeUtils(this).getSettingsTheme());
super.onCreate(savedInstanceState);
setTheme(new ThemeUtils(this).getSettingsTheme());

ViewGroup root = getRootView();
Toolbar toolbar = (Toolbar) View.inflate(this, R.layout.toolbar_without_progressbar, null);
toolbar.setTitle(R.string.general_preferences);
View shadow = View.inflate(this, R.layout.toolbar_action_bar_shadow, null);

root.addView(toolbar, 0);
root.addView(shadow, 1);
setTitle(R.string.general_preferences);
if (savedInstanceState == null) {
getFragmentManager()
.beginTransaction()
.add(android.R.id.content, GeneralPreferencesFragment.newInstance(getIntent().getBooleanExtra(INTENT_KEY_ADMIN_MODE, false)), TAG)
.commit();
}
}

@Override
protected void onPause() {
super.onPause();
Collect.getInstance().initProperties();
}

private ViewGroup getRootView() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
return (ViewGroup) findViewById(android.R.id.list).getParent().getParent().getParent();
} else {
return (ViewGroup) findViewById(android.R.id.list).getParent();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatRadioButton;
import android.text.method.LinkMovementMethod;
import android.util.TypedValue;
import android.view.Gravity;
Expand Down Expand Up @@ -148,7 +149,7 @@ protected RadioButton createRadioButton(int index) {
choiceDisplayName = "";
}

RadioButton radioButton = new RadioButton(getContext());
AppCompatRadioButton radioButton = new AppCompatRadioButton(getContext());
radioButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, getAnswerFontSize());
radioButton.setText(choiceDisplayName);
radioButton.setMovementMethod(LinkMovementMethod.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package org.odk.collect.android.widgets;

import android.content.Context;
import android.support.v7.widget.AppCompatCheckBox;
import android.util.TypedValue;
import android.widget.CheckBox;

import org.javarosa.core.model.data.BooleanData;
import org.javarosa.core.model.data.IAnswerData;
Expand All @@ -28,7 +28,7 @@

public class BooleanWidget extends QuestionWidget {

private CheckBox booleanButton;
private AppCompatCheckBox booleanButton;
private FormEntryPrompt prompt;

public BooleanWidget(Context context, FormEntryPrompt prompt) {
Expand Down Expand Up @@ -68,7 +68,7 @@ private void readSavedAnswer() {
}

private void setupBooleanButton() {
booleanButton = new CheckBox(getContext());
booleanButton = new AppCompatCheckBox(getContext());
booleanButton.setId(ViewIds.generateViewId());
booleanButton.setText(getContext().getString(R.string.trigger));
booleanButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, getAnswerFontSize());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.AppCompatCheckBox;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Gravity;
Expand Down Expand Up @@ -100,7 +101,7 @@ public ListMultiWidget(Context context, FormEntryPrompt prompt, boolean displayL
if (items != null) {
for (int i = 0; i < items.size(); i++) {

CheckBox c = new CheckBox(getContext());
AppCompatCheckBox c = new AppCompatCheckBox(getContext());
c.setTag(i);
c.setId(ViewIds.generateViewId());
c.setFocusable(!prompt.isReadOnly());
Expand Down
Loading

0 comments on commit db0e7f5

Please sign in to comment.