forked from getodk/collect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request getodk#2237 from grzesiek2010/COLLECT-2230
Fixed RadioButtons and CheckBoxes in Dark Theme.
- Loading branch information
Showing
18 changed files
with
198 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...ect_app/src/main/java/org/odk/collect/android/preferences/GeneralPreferencesFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 20 additions & 94 deletions
114
collect_app/src/main/java/org/odk/collect/android/preferences/PreferencesActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.