Skip to content

Commit

Permalink
Merge remote-tracking branch 'hotfix-2.1.1' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Schwengler committed Sep 27, 2018
2 parents 207096c + c9f2744 commit ce7ec7e
Show file tree
Hide file tree
Showing 80 changed files with 683 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package org.catrobat.paintroid.test.espresso;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

Expand All @@ -30,19 +32,55 @@
import org.junit.runner.RunWith;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.pressBack;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;

import static org.catrobat.paintroid.test.espresso.util.EspressoUtils.longClickOnTool;
import static org.catrobat.paintroid.test.espresso.util.wrappers.NavigationDrawerInteraction.onNavigationDrawer;
import static org.hamcrest.Matchers.not;

@RunWith(AndroidJUnit4.class)
public class MainActivityIntegrationTest {

@Rule
public ActivityTestRule<MainActivity> launchActivityRule = new ActivityTestRule<>(MainActivity.class);

@Test
public void testNavigationDrawerMenuAboutTextIsCorrect() {

onNavigationDrawer()
.performOpen();

onView(withText(R.string.pocketpaint_menu_about))
.perform(click());

Context context = InstrumentationRegistry.getTargetContext();
String aboutTextExpected = context.getString(R.string.pocketpaint_about_content,
context.getString(R.string.pocketpaint_about_license));

onView(withText(aboutTextExpected))
.check(matches(isDisplayed()));
}

@Test
public void testNavigationDrawerMenuAboutClosesDrawer() {

onNavigationDrawer()
.performOpen();

onView(withText(R.string.pocketpaint_menu_about))
.perform(click());

pressBack();

onView(withId(R.id.pocketpaint_nav_view))
.check(matches(not(isDisplayed())));
}

@Test
public void testHelpDialogForBrush() {
toolHelpTest(ToolType.BRUSH, R.string.help_content_brush);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public void testNavigationDrawerItemHelpClick() {
onView(withText(R.string.help_title)).perform(click());
}

@Test
public void testNavigationDrawerItemAboutClick() {
onView(withText(R.string.pocketpaint_about_title)).perform(click());
}

@Test
public void testNavigationDrawerItemFullScreenClick() {
onView(withText(R.string.menu_hide_menu)).perform(click());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.catrobat.paintroid.tools.implementation.BaseTool;
import org.catrobat.paintroid.ui.BottomBarHorizontalScrollView;
import org.catrobat.paintroid.ui.DrawingSurface;
import org.catrobat.paintroid.ui.KeyboardListener;
import org.catrobat.paintroid.ui.LayerAdapter;
import org.catrobat.paintroid.ui.LayerNavigator;
import org.catrobat.paintroid.ui.MainActivityInteractor;
Expand Down Expand Up @@ -99,6 +100,7 @@ public class MainActivity extends AppCompatActivity implements MainActivityContr
private MainActivityContracts.Presenter presenter;
private DrawerLayoutViewHolder drawerLayoutViewHolder;
private Handler handler = new Handler();
private KeyboardListener keyboardListener;

@Override
public MainActivityContracts.Presenter getPresenter() {
Expand Down Expand Up @@ -190,6 +192,7 @@ private void onCreateMainView() {
presenter = new MainActivityPresenter(this, model, navigator, interactor, topBarViewHolder,
bottomBarViewHolder, drawerLayoutViewHolder, navigationDrawerViewHolder, commandManager);

keyboardListener = new KeyboardListener(drawerLayout);
setTopBarListeners(topBarViewHolder);
setBottomBarListeners(bottomBarViewHolder);
setNavigationViewListeners(navigationDrawerViewHolder);
Expand Down Expand Up @@ -395,6 +398,8 @@ private void onNavigationItemSelected(@NonNull MenuItem item) {
presenter.exitFullscreenClicked();
} else if (i == R.id.pocketpaint_nav_help) {
presenter.showHelpClicked();
} else if (i == R.id.pocketpaint_nav_about) {
presenter.showAboutClicked();
} else {
throw new IllegalArgumentException();
}
Expand Down Expand Up @@ -429,9 +434,7 @@ public void forwardActivityResult(int requestCode, int resultCode, Intent data)

@Override
public boolean isKeyboardShown() {
View activityView = drawerLayoutViewHolder.drawerLayout;
View rootView = activityView.getRootView();
return rootView.getHeight() - activityView.getHeight() > 300;
return keyboardListener.isSoftKeyboardVisible();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ interface Navigator {

void startImportImageActivity(int requestCode);

void showAboutDialog();

void startWelcomeActivity();

void showIndeterminateProgressDialog();
Expand Down Expand Up @@ -130,6 +132,8 @@ void restoreState(boolean isFullScreen, boolean isSaved, boolean isOpenedFromCat

void showHelpClicked();

void showAboutClicked();

void onNewImage();

void onNewImageFromCamera();
Expand Down
102 changes: 102 additions & 0 deletions Paintroid/src/main/java/org/catrobat/paintroid/dialog/AboutDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Paintroid: An image manipulation application for Android.
* Copyright (C) 2010-2015 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.catrobat.paintroid.dialog;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatDialogFragment;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import org.catrobat.paintroid.BuildConfig;
import org.catrobat.paintroid.R;

public class AboutDialog extends AppCompatDialogFragment {

public static AboutDialog newInstance() {
return new AboutDialog();
}

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
if (getShowsDialog()) {
return super.onCreateView(inflater, container, savedInstanceState);
}
return inflater.inflate(R.layout.dialog_pocketpaint_about, container, false);
}

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

TextView aboutVersionView = view.findViewById(R.id.pocketpaint_about_version);
TextView aboutContentView = view.findViewById(R.id.pocketpaint_about_content);
TextView aboutLicenseView = view.findViewById(R.id.pocketpaint_about_license_url);
TextView aboutCatrobatView = view.findViewById(R.id.pocketpaint_about_catrobat_url);

String aboutVersion = getString(R.string.pocketpaint_about_version, BuildConfig.VERSION_NAME);
aboutVersionView.setText(aboutVersion);

String aboutContent = getString(R.string.pocketpaint_about_content,
getString(R.string.pocketpaint_about_license));
aboutContentView.setText(aboutContent);

String licenseUrl = getString(R.string.pocketpaint_about_url_license,
getString(R.string.pocketpaint_about_url_license_description));
aboutLicenseView.setText(Html.fromHtml(licenseUrl));
aboutLicenseView.setMovementMethod(LinkMovementMethod.getInstance());

String catrobatUrl = getString(R.string.pocketpaint_about_url_catrobat,
getString(R.string.pocketpaint_about_url_catrobat_description));
aboutCatrobatView.setText(Html.fromHtml(catrobatUrl));
aboutCatrobatView.setMovementMethod(LinkMovementMethod.getInstance());
}

@NonNull
@Override
@SuppressLint("InflateParams")
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
View layout = inflater.inflate(R.layout.dialog_pocketpaint_about, null);
onViewCreated(layout, savedInstanceState);

return new AlertDialog.Builder(getContext(), R.style.PocketPaintAlertDialog)
.setTitle(R.string.pocketpaint_about_title)
.setView(layout)
.setPositiveButton(R.string.done, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dismiss();
}
})
.create();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ComposeShader;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.graphics.Shader;
import android.os.Build;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
Expand Down Expand Up @@ -200,20 +198,12 @@ private void drawSatValPanel(Canvas canvas) {
satShader = new LinearGradient(rect.left, rect.top, rect.right,
rect.bottom, Color.WHITE, rgb, Shader.TileMode.CLAMP);

if (Build.VERSION.SDK_INT >= 28) {
ComposeShader mShader = new ComposeShader(valShader, satShader,
PorterDuff.Mode.MULTIPLY);
satValPaint.setShader(mShader);

canvas.drawRect(rect, satValPaint);
} else {
satValPaint.setXfermode(null);
satValPaint.setShader(valShader);
canvas.drawRect(rect, satValPaint);
satValPaint.setShader(satShader);
satValPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));
canvas.drawRect(rect, satValPaint);
}
satValPaint.setXfermode(null);
satValPaint.setShader(valShader);
canvas.drawRect(rect, satValPaint);
satValPaint.setShader(satShader);
satValPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.MULTIPLY));
canvas.drawRect(rect, satValPaint);

Point p = satValToPoint(sat, val);
satValTrackerPaint.setColor(0xff000000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ public void showHelpClicked() {
navigator.startWelcomeActivity();
}

@Override
public void showAboutClicked() {
navigator.showAboutDialog();
}

@Override
public void onNewImage() {
DisplayMetrics metrics = view.getDisplayMetrics();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Paintroid: An image manipulation application for Android.
* Copyright (C) 2010-2018 The Catrobat Team
* (<http://developer.catrobat.org/credits>)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package org.catrobat.paintroid.ui;

import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewTreeObserver;

public class KeyboardListener {
private static final int HEIGHT_THRESHOLD = 300;
private boolean isSoftKeyboardVisible;

public KeyboardListener(final View activityRootView) {
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int heightDifference = activityRootView.getRootView().getHeight() - activityRootView.getHeight();
DisplayMetrics displayMetrics = activityRootView.getResources().getDisplayMetrics();
isSoftKeyboardVisible = heightDifference > dpToPx(HEIGHT_THRESHOLD, displayMetrics);
}
});
}

private static float dpToPx(int dpValue, DisplayMetrics displayMetrics) {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, displayMetrics);
}

public boolean isSoftKeyboardVisible() {
return isSoftKeyboardVisible;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.catrobat.paintroid.WelcomeActivity;
import org.catrobat.paintroid.common.Constants;
import org.catrobat.paintroid.contract.MainActivityContracts;
import org.catrobat.paintroid.dialog.AboutDialog;
import org.catrobat.paintroid.dialog.ChooseNewImageDialog;
import org.catrobat.paintroid.dialog.IndeterminateProgressDialog;
import org.catrobat.paintroid.dialog.InfoDialog;
Expand Down Expand Up @@ -108,6 +109,12 @@ public void startWelcomeActivity() {
mainActivity.startActivity(intent);
}

@Override
public void showAboutDialog() {
AboutDialog about = AboutDialog.newInstance();
about.show(mainActivity.getSupportFragmentManager(), Constants.ABOUT_DIALOG_FRAGMENT_TAG);
}

private Fragment getIndeterminateProgressFragment() {
FragmentManager supportFragmentManager = mainActivity.getSupportFragmentManager();
return supportFragmentManager.findFragmentByTag(Constants.INDETERMINATE_FRAGMENT_TAG);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit ce7ec7e

Please sign in to comment.