Skip to content

Commit

Permalink
Merge pull request #24 from Samagra-Development/hotfix/include_collec…
Browse files Browse the repository at this point in the history
…t_changes

Hotfix/include collect changes
  • Loading branch information
chinmoy12c authored Mar 15, 2023
2 parents b531f9b + 2e85334 commit 476e06e
Show file tree
Hide file tree
Showing 20 changed files with 355 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import org.odk.collect.android.support.rules.FormActivityTestRule;
import org.odk.collect.android.support.rules.TestRuleChain;
import org.odk.collect.androidtest.RecordedIntentsRule;
import org.odk.collect.settings.keys.ProjectKeys;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -253,6 +254,6 @@ private Uri createTempFile(String name, String extension) throws IOException {
}

private Uri getUriForFile(File file) {
return FileProvider.getUriForFile(Collect.getInstance(), BuildConfig.APPLICATION_ID + ".provider", file);
return FileProvider.getUriForFile(Collect.getInstance(), ProjectKeys.APP_PROVIDER + ".provider", file);
}
}
19 changes: 10 additions & 9 deletions odk/collect/collect_app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ the specific language governing permissions and limitations under the License.
android:supportsRtl="true"
android:usesCleartextTraffic="true">

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
<!-- Base application should provide this.-->
<!-- <provider-->
<!-- android:name="androidx.core.content.FileProvider"-->
<!-- android:authorities="${applicationId}.provider"-->
<!-- android:exported="false"-->
<!-- android:grantUriPermissions="true">-->
<!-- <meta-data-->
<!-- android:name="android.support.FILE_PROVIDER_PATHS"-->
<!-- android:resource="@xml/provider_paths" />-->
<!-- </provider>-->

<activity android:name=".activities.FirstLaunchActivity"></activity>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.location.LocationManager;
import android.media.MediaPlayer;
import android.net.Uri;
Expand All @@ -51,10 +54,12 @@
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
Expand All @@ -63,6 +68,7 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.core.widget.NestedScrollView;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.LifecycleOwner;
Expand Down Expand Up @@ -264,6 +270,7 @@ public class FormEntryActivity extends CollectAbstractActivity implements Animat

private FormLoaderTask formLoaderTask;

private LinearLayout buttonHolder;
private TextView nextButton;
private TextView backButton;

Expand Down Expand Up @@ -404,8 +411,12 @@ public void onCreate(Bundle savedInstanceState) {
errorMessage = null;

questionHolder = findViewById(R.id.questionholder);
buttonHolder = findViewById(R.id.buttonholder);

// WARNING: ODK Custom Change
getWindow().setStatusBarColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_PRIMARY_COLOR)));
initToolbar();
buttonHolder.setBackgroundColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_FOOTER_COLOR)));

formIndexAnimationHandler = new FormIndexAnimationHandler(this);
menuDelegate = new FormEntryMenuDelegate(
Expand All @@ -423,12 +434,44 @@ public void onCreate(Bundle savedInstanceState) {
swipeHandler.setBeenSwiped(true);
onSwipeForward();
});
// WARNING: ODK Custom changes
nextButton.setBackgroundColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_NAVIGATION_BACKGROUND_COLOR)));
nextButton.setTextColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_NAVIGATION_FOREGROUND_COLOR)));
nextButton.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
nextButton.getViewTreeObserver().removeOnGlobalLayoutListener(this);
Drawable nextArrow = nextButton.getCompoundDrawables()[2];
if (nextArrow != null) {
nextArrow.setColorFilter(
getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_NAVIGATION_FOREGROUND_COLOR)),
PorterDuff.Mode.SRC_IN
);
}
}
});

backButton = findViewById(R.id.form_back_button);
backButton.setOnClickListener(v -> {
swipeHandler.setBeenSwiped(true);
onSwipeBackward();
});
// WARNING: ODK Custom changes
backButton.setBackgroundColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_NAVIGATION_BACKGROUND_COLOR)));
backButton.setTextColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_NAVIGATION_FOREGROUND_COLOR)));
backButton.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
backButton.getViewTreeObserver().removeOnGlobalLayoutListener(this);
Drawable backArrow = backButton.getCompoundDrawables()[0];
if (backArrow != null) {
backArrow.setColorFilter(
getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_NAVIGATION_FOREGROUND_COLOR)),
PorterDuff.Mode.SRC_IN
);
}
}
});

if (savedInstanceState == null) {
mediaLoadingFragment = new MediaLoadingFragment();
Expand Down Expand Up @@ -735,9 +778,28 @@ private String loadSavePoint() {
return null;
}

// WARNING: ODK Custom Changes
private int getColor(String hash) {
try {
return Color.parseColor(hash);
}
catch (Exception e) {
Timber.e(new IllegalArgumentException("Invalid color hash"));
return 0xffffff;
}
}

private void initToolbar() {
Toolbar toolbar = findViewById(R.id.toolbar);
// WARNING: ODK Custom Change
toolbar.setBackgroundColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_BACKGROUND_COLOR)));
toolbar.setTitleTextColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)));
Drawable drawable = toolbar.getOverflowIcon();
if (drawable != null) {
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable.mutate(), getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)));
toolbar.setOverflowIcon(drawable);
}
setSupportActionBar(toolbar);
setTitle(getString(R.string.loading_form));
}
Expand Down Expand Up @@ -949,7 +1011,17 @@ public void setWidgetData(Object data) {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menuDelegate.onCreateOptionsMenu(getMenuInflater(), menu);
return super.onCreateOptionsMenu(menu);
boolean isSuccessful = super.onCreateOptionsMenu(menu);
for (int i = 0; i < menu.size(); i++) {
Drawable menuIcon = menu.getItem(i).getIcon();
if (menuIcon != null) {
menu.getItem(i).getIcon().setColorFilter(
getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)),
PorterDuff.Mode.SRC_IN
);
}
}
return isSuccessful;
}

@Override
Expand All @@ -974,8 +1046,18 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (itemId == R.id.menu_languages) {
createLanguageDialog();
return true;
} else if (itemId == R.id.menu_save) {// don't exit
saveForm(false, InstancesDaoHelper.isInstanceComplete(false, settingsProvider.getUnprotectedSettings().getBoolean(KEY_COMPLETED_DEFAULT), getFormController()), null, true);
} else if (itemId == R.id.menu_save) {
// WARNING: Custom ODK Change, exit on save
saveForm(
settingsProvider.getProtectedSettings().getBoolean(ProtectedProjectKeys.KEY_EXIT_ON_SAVE),
InstancesDaoHelper.isInstanceComplete(
false,
settingsProvider.getUnprotectedSettings().getBoolean(KEY_COMPLETED_DEFAULT),
getFormController()
),
null,
true
);
return true;
}

Expand Down Expand Up @@ -2021,8 +2103,14 @@ public boolean onKeyDown(int keyCode, KeyEvent event) {
DialogFragmentUtils.showIfNotShowing(RecordingWarningDialogFragment.class, getSupportFragmentManager());
return true;
}

showIfNotShowing(QuitFormDialogFragment.class, getSupportFragmentManager());
// WARNING: Custom ODK Changes, back button behaviour changed
FormController formController = getFormController();
if (!settingsProvider.getProtectedSettings().getBoolean(ProtectedProjectKeys.KEY_EXIT_ON_BACK) && formController != null && !formController.isCurrentQuestionFirstInForm()) {
backButton.callOnClick();
}
else {
showIfNotShowing(QuitFormDialogFragment.class, getSupportFragmentManager());
}
return true;
case KeyEvent.KEYCODE_DPAD_RIGHT:
if (event.isAltPressed() && !swipeHandler.beenSwiped()) {
Expand Down Expand Up @@ -2256,6 +2344,8 @@ && new PlayServicesChecker().isGooglePlayServicesAvailable(this)) {
formControllerAvailable(formController);
Intent intent = new Intent(this, FormHierarchyActivity.class);
intent.putExtra(FormHierarchyActivity.EXTRA_SESSION_ID, sessionId);
// WARNING: Custom ODK Changes
intent.putExtra(FormHierarchyActivity.EXTRA_JUMP_TO_BEGINNING, getIntent().getBooleanExtra(FormHierarchyActivity.EXTRA_JUMP_TO_BEGINNING, false));
startActivityForResult(intent, RequestCodes.HIERARCHY_ACTIVITY);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ public void onCreate(Bundle savedInstanceState) {

configureButtons(formController);

// WARNING: Custom ODK Changes
if (getIntent().getBooleanExtra(FormHierarchyActivity.EXTRA_JUMP_TO_BEGINNING, false)) {
jumpBeginningButton.callOnClick();
}

restoreInstanceState(savedInstanceState);

refreshView();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import androidx.core.graphics.drawable.DrawableCompat;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;

Expand All @@ -46,11 +52,14 @@
import org.odk.collect.androidshared.ui.multiclicksafe.MultiClickGuard;
import org.odk.collect.forms.Form;
import org.odk.collect.forms.instances.Instance;
import org.odk.collect.settings.keys.ProjectKeys;

import java.util.Arrays;

import javax.inject.Inject;

import timber.log.Timber;

/**
* Responsible for displaying all the valid instances in the instance directory.
*
Expand All @@ -75,6 +84,19 @@ public class InstanceChooserList extends InstanceListActivity implements Adapter
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.form_chooser_list);
// WARNING: Custom ODK changes
getWindow().setStatusBarColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_PRIMARY_COLOR)));
Toolbar toolbar = findViewById(R.id.toolbar);
if (toolbar != null) {
toolbar.setBackgroundColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_BACKGROUND_COLOR)));
toolbar.setTitleTextColor(getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)));
Drawable drawable = toolbar.getOverflowIcon();
if (drawable != null) {
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable.mutate(), getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)));
toolbar.setOverflowIcon(drawable);
}
}
DaggerUtils.getComponent(this).inject(this);

String formMode = getIntent().getStringExtra(ApplicationConstants.BundleKeys.FORM_MODE);
Expand Down Expand Up @@ -135,6 +157,22 @@ public void onCreate(Bundle savedInstanceState) {
init();
}

// WARNING: Custom ODK changes
@Override
public boolean onCreateOptionsMenu(Menu menu) {
boolean isSuccessful = super.onCreateOptionsMenu(menu);
for (int i = 0; i < menu.size(); i++) {
Drawable menuIcon = menu.getItem(i).getIcon();
if (menuIcon != null) {
menu.getItem(i).getIcon().setColorFilter(
getColor(settingsProvider.getUnprotectedSettings().getString(ProjectKeys.FORM_ACTIVITY_TOOLBAR_FOREGROUND_COLOR)),
PorterDuff.Mode.SRC_IN
);
}
}
return isSuccessful;
}

private void init() {
setupAdapter();
getSupportLoaderManager().initLoader(LOADER_ID, null, this);
Expand Down Expand Up @@ -268,4 +306,15 @@ public void onClick(DialogInterface dialog, int i) {
alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.ok), errorListener);
alertDialog.show();
}

// WARNING: Custom ODK changes
private int getColor(String hash) {
try {
return Color.parseColor(hash);
}
catch (Exception e) {
Timber.e(new IllegalArgumentException("Invalid color hash"));
return 0xffffff;
}
}
}
Loading

0 comments on commit 476e06e

Please sign in to comment.