diff options
Diffstat (limited to 'android/source/src/java')
32 files changed, 457 insertions, 803 deletions
diff --git a/android/source/src/java/org/libreoffice/AboutDialogFragment.java b/android/source/src/java/org/libreoffice/AboutDialogFragment.java index b8e22077e928..0d9fc45856ef 100644 --- a/android/source/src/java/org/libreoffice/AboutDialogFragment.java +++ b/android/source/src/java/org/libreoffice/AboutDialogFragment.java @@ -18,8 +18,8 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.v4.app.DialogFragment; +import androidx.annotation.NonNull; +import androidx.fragment.app.DialogFragment; import android.text.Html; import android.text.Spanned; import android.text.method.LinkMovementMethod; @@ -40,37 +40,27 @@ public class AboutDialogFragment extends DialogFragment { int defaultColor = textView.getTextColors().getDefaultColor(); textView.setTextColor(defaultColor); - // Take care of placeholders in the version and vendor text views. - TextView versionView = messageView.findViewById(R.id.about_version); - TextView vendorView = messageView.findViewById(R.id.about_vendor); + // Take care of placeholders and set text in version and vendor text views. try { String versionName = getActivity().getPackageManager() .getPackageInfo(getActivity().getPackageName(), 0).versionName; - String[] tokens = versionName.split("/"); - if (tokens.length == 3) - { - String version = String.format(versionView.getText().toString().replace("\n", "<br/>"), - tokens[0], "<a href=\"https://hub.libreoffice.org/git-core/" + tokens[1] + "\">" + tokens[1] + "</a>"); - @SuppressWarnings("deprecation") // since 24 with additional option parameter - Spanned versionString = Html.fromHtml(version); - versionView.setText(versionString); - versionView.setMovementMethod(LinkMovementMethod.getInstance()); - String vendor = vendorView.getText().toString(); - vendor = vendor.replace("$VENDOR", tokens[2]); - vendorView.setText(vendor); - } - else - throw new PackageManager.NameNotFoundException(); + String version = String.format(getString(R.string.app_version), versionName, BuildConfig.BUILD_ID_SHORT); + @SuppressWarnings("deprecation") // since 24 with additional option parameter + Spanned versionString = Html.fromHtml(version); + TextView versionView = messageView.findViewById(R.id.about_version); + versionView.setText(versionString); + versionView.setMovementMethod(LinkMovementMethod.getInstance()); + TextView vendorView = messageView.findViewById(R.id.about_vendor); + String vendor = getString(R.string.app_vendor).replace("$VENDOR", BuildConfig.VENDOR); + vendorView.setText(vendor); } catch (PackageManager.NameNotFoundException e) { - versionView.setText(""); - vendorView.setText(""); } AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); - builder .setIcon(R.drawable.lo_icon) + builder .setIcon(R.mipmap.ic_launcher) .setTitle(R.string.app_name) .setView(messageView) .setNegativeButton(R.string.about_license, new DialogInterface.OnClickListener() { @@ -86,15 +76,19 @@ public class AboutDialogFragment extends DialogFragment { loadFromAbout(R.raw.notice); dialog.dismiss(); } - }) - .setNeutralButton(R.string.about_moreinfo, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int id) { - loadFromAbout(R.raw.example); - dialog.dismiss(); - } }); + // when privacy policy URL is set (via '--with-privacy-policy-url=<url>' autogen option), + // add button to open that URL + final String privacyUrl = BuildConfig.PRIVACY_POLICY_URL; + if (!privacyUrl.isEmpty() && privacyUrl != "undefined") { + builder.setNeutralButton(R.string.about_privacy_policy, (DialogInterface dialog, int id) -> { + Intent openPrivacyUrlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(privacyUrl)); + startActivity(openPrivacyUrlIntent); + dialog.dismiss(); + }); + } + return builder.create(); } diff --git a/android/source/src/java/org/libreoffice/ColorPaletteAdapter.java b/android/source/src/java/org/libreoffice/ColorPaletteAdapter.java index 6ec6aa138f66..16d8a977864f 100644 --- a/android/source/src/java/org/libreoffice/ColorPaletteAdapter.java +++ b/android/source/src/java/org/libreoffice/ColorPaletteAdapter.java @@ -1,7 +1,7 @@ package org.libreoffice; import android.content.Context; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -12,12 +12,12 @@ import android.widget.ImageButton; public class ColorPaletteAdapter extends RecyclerView.Adapter<ColorPaletteAdapter.ColorPaletteViewHolder> { - int[][] color_palette; - Context mContext; - int upperSelectedBox = -1; - int selectedBox = 0; - boolean animate; - ColorPaletteListener colorPaletteListener; + private int[][] color_palette; + private final Context mContext; + private int upperSelectedBox = -1; + private int selectedBox = 0; + private boolean animate; + private final ColorPaletteListener colorPaletteListener; public ColorPaletteAdapter(Context mContext, ColorPaletteListener colorPaletteListener) { this.mContext = mContext; @@ -36,6 +36,10 @@ public class ColorPaletteAdapter extends RecyclerView.Adapter<ColorPaletteAdapte return selectedBox; } + public int getUpperSelectedBox() { + return upperSelectedBox; + } + @Override public void onBindViewHolder(final ColorPaletteViewHolder holder, int position) { @@ -128,4 +132,4 @@ public class ColorPaletteAdapter extends RecyclerView.Adapter<ColorPaletteAdapte } -}
\ No newline at end of file +} diff --git a/android/source/src/java/org/libreoffice/ColorPickerAdapter.java b/android/source/src/java/org/libreoffice/ColorPickerAdapter.java index c93d5a01bbb4..a17dd264fb99 100644 --- a/android/source/src/java/org/libreoffice/ColorPickerAdapter.java +++ b/android/source/src/java/org/libreoffice/ColorPickerAdapter.java @@ -3,7 +3,7 @@ package org.libreoffice; import android.content.Context; import android.content.res.Resources; import android.graphics.Color; -import android.support.v7.widget.RecyclerView; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -12,12 +12,11 @@ import android.widget.ImageButton; public class ColorPickerAdapter extends RecyclerView.Adapter<ColorPickerAdapter.ColorPickerViewHolder> { - Context mContext; - ColorPaletteAdapter colorPaletteAdapter; - ColorPaletteListener colorPaletteListener; - int[] colorList; - int[][] colorPalette = new int[11][8]; - int selectedBox = 0; + private final Context mContext; + private final ColorPaletteAdapter colorPaletteAdapter; + private final ColorPaletteListener colorPaletteListener; + private final int[] colorList; + private final int[][] colorPalette = new int[11][8]; public ColorPickerAdapter(Context mContext, final ColorPaletteAdapter colorPaletteAdapter, ColorPaletteListener colorPaletteListener) { this.mContext = mContext; @@ -41,10 +40,11 @@ public class ColorPickerAdapter extends RecyclerView.Adapter<ColorPickerAdapter. public void onBindViewHolder(final ColorPickerViewHolder holder, int position) { holder.colorBox.setBackgroundColor(colorList[position]); - if (selectedBox != position) - holder.colorBox.setImageDrawable(null); - else { + if (colorPaletteAdapter.getUpperSelectedBox() == position + && colorPaletteAdapter.getSelectedBox() >= 0) { holder.colorBox.setImageResource(R.drawable.ic_done_white_12dp); + } else { + holder.colorBox.setImageDrawable(null); } holder.colorBox.setOnClickListener(new View.OnClickListener() { @@ -64,12 +64,20 @@ public class ColorPickerAdapter extends RecyclerView.Adapter<ColorPickerAdapter. private void setPosition(int position) { - this.selectedBox = position; selectSubColor(position, position==0?0:3); colorPaletteListener.applyColor(colorList[position]); updateAdapter(); } + /** + * Switches to first palette, but doesn't mark any color as selected. + * Use this if no color in the palette matches the actual one. + */ + public void unselectColors() { + colorPaletteAdapter.changePosition(0, -1); + updateAdapter(); + } + private void selectSubColor(int position1, int position2) { colorPaletteAdapter.setPosition(position1, position2); } @@ -88,7 +96,15 @@ public class ColorPickerAdapter extends RecyclerView.Adapter<ColorPickerAdapter. int red_shade = red; int green_shade = green; int blue_shade = blue; - if (i != 0) { + if (i == 0) { + colorPalette[0][0] = colorList[i]; + for (int k = 1; k < 7; k++) { + red_tint = (int) (red_tint + (255 - red_tint) * 0.25); + green_tint = (int) (green_tint + (255 - green_tint) * 0.25); + blue_tint = (int) (blue_tint + (255 - blue_tint) * 0.25); + colorPalette[i][k] = (Color.rgb(red_tint, green_tint, blue_tint)); + } + } else { colorPalette[i][3] = colorList[i]; for (int k = 2; k >= 0; k--) { red_shade = (int) (red_shade * 0.75); @@ -102,48 +118,28 @@ public class ColorPickerAdapter extends RecyclerView.Adapter<ColorPickerAdapter. blue_tint = (int) (blue_tint + (255 - blue_tint) * 0.45); colorPalette[i][k] = (Color.rgb(red_tint, green_tint, blue_tint)); } - } else { - colorPalette[0][0] = colorList[i]; - for (int k = 1; k < 7; k++) { - red_tint = (int) (red_tint + (255 - red_tint) * 0.25); - green_tint = (int) (green_tint + (255 - green_tint) * 0.25); - blue_tint = (int) (blue_tint + (255 - blue_tint) * 0.25); - colorPalette[i][k] = (Color.rgb(red_tint, green_tint, blue_tint)); - } } - } - for (int i = 0; i < 11; i++){ - this.colorPalette[i][7] = (Color.rgb(255, 255, 255)); // last one is always white + colorPalette[i][7] = Color.WHITE; // last one is always white } colorPaletteAdapter.setColorPalette(colorPalette); } public void findSelectedTextColor(int color) { - /* - Libreoffice recognizes -1 as Black - */ - if (color == -1) { - colorPaletteAdapter.changePosition(0, 0); - selectedBox = 0; - updateAdapter(); - return; - } - /* - Find the color if the palette points another color - */ - if (colorPalette[selectedBox][colorPaletteAdapter.getSelectedBox()] != color) { - for (int i = 0; i < 11; i++) { - for (int k = 0; k < 8; k++) { - if (colorPalette[i][k] == color) { - colorPaletteAdapter.changePosition(i, k); - selectedBox = i; - updateAdapter(); - return; - } + // try to find and highlight the color in the existing palettes + for (int i = 0; i < 11; i++) { + for (int k = 0; k < 8; k++) { + if (colorPalette[i][k] == color) { + colorPaletteAdapter.changePosition(i, k); + updateAdapter(); + return; } } } + + // no color in the palettes matched + unselectColors(); } + private void updateAdapter(){ LOKitShell.getMainHandler().post(new Runnable() { @Override @@ -163,4 +159,4 @@ public class ColorPickerAdapter extends RecyclerView.Adapter<ColorPickerAdapter. this.colorBox = itemView.findViewById(R.id.fontColorBox); } } -}
\ No newline at end of file +} diff --git a/android/source/src/java/org/libreoffice/FontController.java b/android/source/src/java/org/libreoffice/FontController.java index 8729b51e01ac..72f35d8b42d8 100644 --- a/android/source/src/java/org/libreoffice/FontController.java +++ b/android/source/src/java/org/libreoffice/FontController.java @@ -2,12 +2,13 @@ package org.libreoffice; import android.graphics.Color; import android.graphics.Rect; -import android.support.design.widget.BottomSheetBehavior; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.RecyclerView; +import com.google.android.material.bottomsheet.BottomSheetBehavior; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; +import android.widget.Button; import android.widget.ImageButton; import android.widget.LinearLayout; import android.widget.RelativeLayout; @@ -23,12 +24,15 @@ import java.util.Iterator; public class FontController implements AdapterView.OnItemSelectedListener { + /** -1 as value in ".uno:Color" et al. means "automatic color"/no color set. */ + private static final int COLOR_AUTO = -1; + private boolean mFontNameSpinnerSet = false; private boolean mFontSizeSpinnerSet = false; private final LibreOfficeMainActivity mActivity; - private final ArrayList<String> mFontList = new ArrayList<String>(); - private final ArrayList<String> mFontSizes = new ArrayList<String>(); - private final HashMap<String, ArrayList<String>> mAllFontSizes = new HashMap<String, ArrayList<String>>(); + private final ArrayList<String> mFontList = new ArrayList<>(); + private final ArrayList<String> mFontSizes = new ArrayList<>(); + private final HashMap<String, ArrayList<String>> mAllFontSizes = new HashMap<>(); private String mCurrentFontSelected = null; private String mCurrentFontSizeSelected = null; @@ -45,29 +49,44 @@ public class FontController implements AdapterView.OnItemSelectedListener { final ColorPaletteListener colorPaletteListener = new ColorPaletteListener() { @Override public void applyColor(int color) { - sendFontColorChange(color); + sendFontColorChange(color, false); } @Override public void updateColorPickerPosition(int color) { - if (null == colorPickerAdapter) return; - colorPickerAdapter.findSelectedTextColor(color + 0xFF000000); - changeFontColorBoxColor(color + 0xFF000000); + if (colorPickerAdapter == null) { + return; + } + if (color == COLOR_AUTO) { + colorPickerAdapter.unselectColors(); + changeFontColorBoxColor(Color.TRANSPARENT); + return; + } + final int colorWithAlpha = color | 0xFF000000; + colorPickerAdapter.findSelectedTextColor(colorWithAlpha); + changeFontColorBoxColor(colorWithAlpha); } }; final ColorPaletteListener backColorPaletteListener = new ColorPaletteListener() { @Override public void applyColor(int color) { - sendFontBackColorChange(color); + sendFontBackColorChange(color, false); } @Override public void updateColorPickerPosition(int color) { - if(backColorPickerAdapter != null) - backColorPickerAdapter.findSelectedTextColor(color + 0xFF000000); - changeFontBackColorBoxColor(color + 0xFF000000); - + if (backColorPickerAdapter == null) { + return; + } + if (color == COLOR_AUTO) { + backColorPickerAdapter.unselectColors(); + changeFontBackColorBoxColor(Color.TRANSPARENT); + return; + } + final int colorWithAlpha = color | 0xFF000000; + backColorPickerAdapter.findSelectedTextColor(colorWithAlpha); + changeFontBackColorBoxColor(colorWithAlpha); } }; @@ -77,11 +96,7 @@ public class FontController implements AdapterView.OnItemSelectedListener { LOKitShell.getMainHandler().post(new Runnable() { @Override public void run() { - if(color == -1){ //Libreoffice recognizes -1 as black - fontColorPickerButton.setBackgroundColor(Color.BLACK); - }else{ - fontColorPickerButton.setBackgroundColor(color); - } + fontColorPickerButton.setBackgroundColor(color); } }); } @@ -92,12 +107,7 @@ public class FontController implements AdapterView.OnItemSelectedListener { LOKitShell.getMainHandler().post(new Runnable() { @Override public void run() { - if(color == -1){ //Libreoffice recognizes -1 as black - fontBackColorPickerButton.setBackgroundColor(Color.BLACK); - }else{ - fontBackColorPickerButton.setBackgroundColor(color); - - } + fontBackColorPickerButton.setBackgroundColor(color); } }); } @@ -132,12 +142,12 @@ public class FontController implements AdapterView.OnItemSelectedListener { } } - private void sendFontColorChange(int color){ + private void sendFontColorChange(int color, boolean keepAlpha){ try { JSONObject json = new JSONObject(); JSONObject valueJson = new JSONObject(); valueJson.put("type", "long"); - valueJson.put("value", 0x00FFFFFF & color); + valueJson.put("value", keepAlpha ? color : 0x00FFFFFF & color); json.put("Color", valueJson); LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Color", json.toString())); @@ -152,21 +162,18 @@ public class FontController implements AdapterView.OnItemSelectedListener { * 0x00FFFFFF & color operation removes the alpha which is FF, * if we don't remove it, the color value becomes negative which is not recognized by LOK */ - private void sendFontBackColorChange(int color){ + private void sendFontBackColorChange(int color, boolean keepAlpha) { try { JSONObject json = new JSONObject(); JSONObject valueJson = new JSONObject(); valueJson.put("type", "long"); - valueJson.put("value", 0x00FFFFFF & color); + valueJson.put("value", keepAlpha ? color : 0x00FFFFFF & color); if(mActivity.getTileProvider().isSpreadsheet()){ json.put("BackgroundColor", valueJson); LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:BackgroundColor", json.toString())); - }else if(mActivity.getTileProvider().isPresentation()){ + }else { json.put("CharBackColor", valueJson); LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:CharBackColor", json.toString())); - }else { - json.put("BackColor", valueJson); - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:BackColor", json.toString())); } changeFontBackColorBoxColor(color); @@ -213,7 +220,7 @@ public class FontController implements AdapterView.OnItemSelectedListener { String key = keys.next(); mFontList.add(key); JSONArray array = jObject2.getJSONArray(key); - fontSizes = new ArrayList<String>(); + fontSizes = new ArrayList<>(); for (int i = 0; i < array.length(); i++) { fontSizes.add(array.getString(i)); } @@ -237,14 +244,14 @@ public class FontController implements AdapterView.OnItemSelectedListener { private void setupFontNameSpinner() { Spinner fontSpinner = mActivity.findViewById(R.id.font_name_spinner); - ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(mActivity, android.R.layout.simple_spinner_item, mFontList); + ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(mActivity, android.R.layout.simple_spinner_item, mFontList); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); fontSpinner.setAdapter(dataAdapter); } private void setupFontSizeSpinner() { Spinner fontSizeSpinner = mActivity.findViewById(R.id.font_size_spinner); - ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(mActivity, android.R.layout.simple_spinner_item, mFontSizes); + ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(mActivity, android.R.layout.simple_spinner_item, mFontSizes); dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); fontSizeSpinner.setAdapter(dataAdapter); } @@ -306,6 +313,10 @@ public class FontController implements AdapterView.OnItemSelectedListener { fontColorPicker.setOnClickListener(clickListener); fontColorPickerButton.setOnClickListener(clickListener); + final Button autoColorButton = colorPickerLayout.findViewById(R.id.button_auto_color); + autoColorButton.setOnClickListener(view -> { + sendFontColorChange(COLOR_AUTO, true); + }); } private void setupBackColorPicker(){ @@ -365,6 +376,10 @@ public class FontController implements AdapterView.OnItemSelectedListener { fontColorPicker.setOnClickListener(clickListener); fontColorPickerButton.setOnClickListener(clickListener); + final Button autoColorButton = backColorPickerLayout.findViewById(R.id.button_auto_color); + autoColorButton.setOnClickListener(view -> { + sendFontBackColorChange(COLOR_AUTO, true); + }); } public void selectFont(final String fontName) { diff --git a/android/source/src/java/org/libreoffice/FormattingController.java b/android/source/src/java/org/libreoffice/FormattingController.java index 9259b2ea6cae..49e81eb69784 100644 --- a/android/source/src/java/org/libreoffice/FormattingController.java +++ b/android/source/src/java/org/libreoffice/FormattingController.java @@ -11,8 +11,8 @@ import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Environment; import android.provider.MediaStore; -import android.support.design.widget.Snackbar; -import android.support.v4.content.FileProvider; +import com.google.android.material.snackbar.Snackbar; +import androidx.core.content.FileProvider; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -48,6 +48,8 @@ class FormattingController implements View.OnClickListener { mContext.findViewById(R.id.button_insertFormatListBullets).setOnClickListener(this); mContext.findViewById(R.id.button_insertFormatListNumbering).setOnClickListener(this); + mContext.findViewById(R.id.button_increaseIndent).setOnClickListener(this); + mContext.findViewById(R.id.button_decreaseIndent).setOnClickListener(this); mContext.findViewById(R.id.button_bold).setOnClickListener(this); mContext.findViewById(R.id.button_italic).setOnClickListener(this); @@ -84,70 +86,51 @@ class FormattingController implements View.OnClickListener { button.getBackground().setState(new int[]{android.R.attr.state_selected}); } - switch(button.getId()) { - - case R.id.button_insertFormatListBullets: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:DefaultBullet")); - break; - - case R.id.button_insertFormatListNumbering: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:DefaultNumbering")); - break; - - case R.id.button_bold: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Bold")); - break; - case R.id.button_italic: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Italic")); - break; - case R.id.button_strikethrough: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Strikeout")); - break; - case R.id.button_clearformatting: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:ResetAttributes")); - break; - case R.id.button_underlined: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:UnderlineDouble")); - break; - case R.id.button_align_left: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:LeftPara")); - break; - case R.id.button_align_center: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:CenterPara")); - break; - case R.id.button_align_right: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:RightPara")); - break; - case R.id.button_align_justify: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:JustifyPara")); - break; - case R.id.button_insert_line: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Line")); - break; - case R.id.button_insert_rect: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Rect")); - break; - case R.id.button_font_shrink: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Shrink")); - break; - case R.id.button_font_grow: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Grow")); - break; - case R.id.button_subscript: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:SubScript")); - break; - case R.id.button_superscript: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:SuperScript")); - break; - case R.id.button_insert_picture: - insertPicture(); - break; - case R.id.button_insert_table: - insertTable(); - break; - case R.id.button_delete_table: - deleteTable(); - break; + final int buttonId = button.getId(); + if (buttonId == R.id.button_insertFormatListBullets) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:DefaultBullet")); + } else if (buttonId == R.id.button_insertFormatListNumbering) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:DefaultNumbering")); + } else if (buttonId == R.id.button_increaseIndent) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:IncrementIndent")); + } else if (buttonId == R.id.button_decreaseIndent) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:DecrementIndent")); + } else if (buttonId == R.id.button_bold) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Bold")); + } else if (buttonId == R.id.button_italic) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Italic")); + } else if (buttonId == R.id.button_strikethrough) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Strikeout")); + } else if (buttonId == R.id.button_clearformatting) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:ResetAttributes")); + } else if (buttonId == R.id.button_underlined) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:UnderlineDouble")); + } else if (buttonId == R.id.button_align_left) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:LeftPara")); + } else if (buttonId == R.id.button_align_center) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:CenterPara")); + } else if (buttonId == R.id.button_align_right) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:RightPara")); + } else if (buttonId == R.id.button_align_justify) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:JustifyPara")); + } else if (buttonId == R.id.button_insert_line) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Line")); + } else if (buttonId == R.id.button_insert_rect) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Rect")); + } else if (buttonId == R.id.button_font_shrink) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Shrink")); + } else if (buttonId == R.id.button_font_grow) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Grow")); + } else if (buttonId == R.id.button_subscript) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:SubScript")); + }else if (buttonId == R.id.button_superscript) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:SuperScript")); + } else if (buttonId == R.id.button_insert_picture) { + insertPicture(); + } else if (buttonId == R.id.button_insert_table) { + insertTable(); + } else if (buttonId == R.id.button_delete_table) { + deleteTable(); } } @@ -243,15 +226,11 @@ class FormattingController implements View.OnClickListener { public void onClick(View v) { int rowCount = Integer.parseInt(npRowCount.getText().toString()); int colCount = Integer.parseInt(npColCount.getText().toString()); - switch (v.getId()){ - case R.id.number_picker_rows_positive: - if(rowCount < maxValue) - npRowCount.setText(String.valueOf(++rowCount)); - break; - case R.id.number_picker_cols_positive: - if(colCount < maxValue) - npColCount.setText(String.valueOf(++colCount)); - break; + final int id = v.getId(); + if (id == R.id.number_picker_rows_positive && rowCount < maxValue) { + npRowCount.setText(String.valueOf(++rowCount)); + } else if (id == R.id.number_picker_cols_positive && colCount < maxValue) { + npColCount.setText(String.valueOf(++colCount)); } } }; @@ -261,15 +240,11 @@ class FormattingController implements View.OnClickListener { public void onClick(View v) { int rowCount = Integer.parseInt(npRowCount.getText().toString()); int colCount = Integer.parseInt(npColCount.getText().toString()); - switch (v.getId()){ - case R.id.number_picker_rows_negative: - if(rowCount > minValue) - npRowCount.setText(String.valueOf(--rowCount)); - break; - case R.id.number_picker_cols_negative: - if(colCount > minValue) - npColCount.setText(String.valueOf(--colCount)); - break; + final int id = v.getId(); + if (id == R.id.number_picker_rows_negative && rowCount > minValue) { + npRowCount.setText(String.valueOf(--rowCount)); + } else if (id == R.id.number_picker_cols_negative && colCount > minValue) { + npColCount.setText(String.valueOf(--colCount)); } } }; diff --git a/android/source/src/java/org/libreoffice/InvalidationHandler.java b/android/source/src/java/org/libreoffice/InvalidationHandler.java index 0f3f1dd7b889..c48127cce67f 100644 --- a/android/source/src/java/org/libreoffice/InvalidationHandler.java +++ b/android/source/src/java/org/libreoffice/InvalidationHandler.java @@ -342,7 +342,7 @@ public class InvalidationHandler implements Document.MessageCallback, Office.Mes mContext.getFormattingController().onToggleStateChanged(Document.NUMBERED_LIST, pressed); } else if (parts[0].equals(".uno:Color")) { mContext.getFontController().colorPaletteListener.updateColorPickerPosition(Integer.parseInt(value)); - } else if (mContext.getTileProvider().isTextDocument() && parts[0].equals(".uno:BackColor")) { + } else if (mContext.getTileProvider().isTextDocument() && (parts[0].equals(".uno:BackColor") || parts[0].equals(".uno:CharBackColor"))) { mContext.getFontController().backColorPaletteListener.updateColorPickerPosition(Integer.parseInt(value)); } else if (mContext.getTileProvider().isPresentation() && parts[0].equals(".uno:CharBackColor")) { mContext.getFontController().backColorPaletteListener.updateColorPickerPosition(Integer.parseInt(value)); diff --git a/android/source/src/java/org/libreoffice/LOKitThread.java b/android/source/src/java/org/libreoffice/LOKitThread.java index a4d5ba99f1a2..fd40c3089102 100644 --- a/android/source/src/java/org/libreoffice/LOKitThread.java +++ b/android/source/src/java/org/libreoffice/LOKitThread.java @@ -184,9 +184,11 @@ class LOKitThread extends Thread { private void updateZoomConstraints() { if (mTileProvider == null) return; mLayerClient = mContext.getLayerClient(); - // Set min zoom to the page width so that you cannot zoom below page width - final float minZoom = mLayerClient.getViewportMetrics().getWidth()/mTileProvider.getPageWidth(); - mLayerClient.setZoomConstraints(new ZoomConstraints(true, 1f, minZoom, 0f)); + // Set default zoom to the page width and min zoom so that the whole page is visible + final float pageHeightZoom = mLayerClient.getViewportMetrics().getHeight() / mTileProvider.getPageHeight(); + final float pageWidthZoom = mLayerClient.getViewportMetrics().getWidth() / mTileProvider.getPageWidth(); + final float minZoom = Math.min(pageWidthZoom, pageHeightZoom); + mLayerClient.setZoomConstraints(new ZoomConstraints(pageWidthZoom, minZoom, 0f)); } /** @@ -204,8 +206,9 @@ class LOKitThread extends Thread { /** * Handle load document event. * @param filePath - filePath to where the document is located + * @return Whether the document has been loaded successfully. */ - private void loadDocument(String filePath) { + private boolean loadDocument(String filePath) { mLayerClient = mContext.getLayerClient(); mInvalidationHandler = new InvalidationHandler(mContext); @@ -214,18 +217,12 @@ class LOKitThread extends Thread { if (mTileProvider.isReady()) { LOKitShell.showProgressSpinner(mContext); updateZoomConstraints(); - LOKitShell.getMainHandler().post(new Runnable() { - @Override - public void run() { - // synchronize to avoid deletion while loading - synchronized (LOKitThread.this) { - refresh(true); - } - } - }); + refresh(true); LOKitShell.hideProgressSpinner(mContext); + return true; } else { closeDocument(); + return false; } } @@ -235,20 +232,9 @@ class LOKitThread extends Thread { * @param fileType - fileType what type of new document is to be loaded */ private void loadNewDocument(String filePath, String fileType) { - mLayerClient = mContext.getLayerClient(); - - mInvalidationHandler = new InvalidationHandler(mContext); - mTileProvider = TileProviderFactory.create(mContext, mInvalidationHandler, fileType); - - if (mTileProvider.isReady()) { - LOKitShell.showProgressSpinner(mContext); - updateZoomConstraints(); - refresh(true); - LOKitShell.hideProgressSpinner(mContext); - + boolean ok = loadDocument(fileType); + if (ok) { mTileProvider.saveDocumentAs(filePath, true); - } else { - closeDocument(); } } @@ -266,8 +252,7 @@ class LOKitThread extends Thread { /** * Close the currently loaded document. */ - // needs to be synchronized to not destroy doc while it's loaded - private synchronized void closeDocument() { + private void closeDocument() { if (mTileProvider != null) { mTileProvider.close(); mTileProvider = null; diff --git a/android/source/src/java/org/libreoffice/LOKitTileProvider.java b/android/source/src/java/org/libreoffice/LOKitTileProvider.java index 579162931d3a..5d1cf12209dc 100644 --- a/android/source/src/java/org/libreoffice/LOKitTileProvider.java +++ b/android/source/src/java/org/libreoffice/LOKitTileProvider.java @@ -120,27 +120,9 @@ class LOKitTileProvider implements TileProvider { private void postLoad() { mDocument.setMessageCallback(mMessageCallback); - int parts = mDocument.getParts(); - Log.i(LOGTAG, "Document parts: " + parts); - mContext.getDocumentPartView().clear(); - + resetParts(); // Writer documents always have one part, so hide the navigation drawer. - if (mDocument.getDocumentType() != Document.DOCTYPE_TEXT) { - for (int i = 0; i < parts; i++) { - String partName = mDocument.getPartName(i); - if (partName.isEmpty()) { - partName = getGenericPartName(i); - }else if (partName.startsWith("Slide") || partName.startsWith("Sheet") || partName.startsWith("Part")) { - partName = getGenericPartName(i); - } - Log.i(LOGTAG, "Document part " + i + " name:'" + partName + "'"); - - mDocument.setPart(i); - resetDocumentSize(); - final DocumentPartView partView = new DocumentPartView(i, partName); - mContext.getDocumentPartView().add(partView); - } - } else { + if (mDocument.getDocumentType() == Document.DOCTYPE_TEXT) { mContext.disableNavigationDrawer(); mContext.getToolbarController().hideItem(R.id.action_parts); } @@ -194,9 +176,9 @@ class LOKitTileProvider implements TileProvider { } public void resetParts(){ - int parts = mDocument.getParts(); mContext.getDocumentPartView().clear(); if (mDocument.getDocumentType() != Document.DOCTYPE_TEXT) { + int parts = mDocument.getParts(); for (int i = 0; i < parts; i++) { String partName = mDocument.getPartName(i); @@ -210,7 +192,9 @@ class LOKitTileProvider implements TileProvider { mContext.getDocumentPartView().add(partView); } } - } public void renamePart(String partName) { + } + + public void renamePart(String partName) { try{ for(int i=0; i<mDocument.getParts(); i++){ if(mContext.getDocumentPartView().get(i).partName.equals(partName)){ @@ -329,11 +313,6 @@ class LOKitTileProvider implements TileProvider { } public void printDocument() { - if (Build.VERSION.SDK_INT < 19) { - mContext.showCustomStatusMessage(mContext.getString(R.string.printing_not_supported)); - return; - } - String mInputFileName = (new File(mInputFile)).getName(); String file = mInputFileName.substring(0,(mInputFileName.length()-3))+"pdf"; String cacheFile = mContext.getExternalCacheDir().getAbsolutePath() + "/" + file; diff --git a/android/source/src/java/org/libreoffice/LibreOfficeApplication.java b/android/source/src/java/org/libreoffice/LibreOfficeApplication.java index cb79219fc999..ebe54cf27c64 100644 --- a/android/source/src/java/org/libreoffice/LibreOfficeApplication.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeApplication.java @@ -10,11 +10,11 @@ package org.libreoffice; -import android.app.Application; import android.content.Context; import android.os.Handler; +import androidx.multidex.MultiDexApplication; -public class LibreOfficeApplication extends Application { +public class LibreOfficeApplication extends MultiDexApplication { private static Handler mainHandler; diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java index 5ce176716d66..cf60ff37c5da 100644 --- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -15,11 +15,11 @@ import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; import android.provider.DocumentsContract; -import android.support.design.widget.BottomSheetBehavior; -import android.support.design.widget.Snackbar; -import android.support.v4.widget.DrawerLayout; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; +import com.google.android.material.bottomsheet.BottomSheetBehavior; +import com.google.android.material.snackbar.Snackbar; +import androidx.drawerlayout.widget.DrawerLayout; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; import android.text.InputType; import android.util.Log; import android.view.KeyEvent; @@ -60,7 +60,7 @@ import java.util.UUID; public class LibreOfficeMainActivity extends AppCompatActivity implements SettingsListenerModel.OnSettingsPreferenceChangedListener { private static final String LOGTAG = "LibreOfficeMainActivity"; - private static final String ENABLE_EXPERIMENTAL_PREFS_KEY = "ENABLE_EXPERIMENTAL"; + public static final String ENABLE_EXPERIMENTAL_PREFS_KEY = "ENABLE_EXPERIMENTAL"; private static final String ASSETS_EXTRACTED_PREFS_KEY = "ASSETS_EXTRACTED"; private static final String ENABLE_DEVELOPER_PREFS_KEY = "ENABLE_DEVELOPER"; private static final int REQUEST_CODE_SAVEAS = 12345; @@ -324,7 +324,9 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin intent.addCategory(Intent.CATEGORY_OPENABLE); String mimeType = getODFMimeTypeForDocument(); intent.setType(mimeType); - intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, mDocumentUri); + if (Build.VERSION.SDK_INT >= 26) { + intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, mDocumentUri); + } startActivityForResult(intent, REQUEST_CODE_SAVEAS); } @@ -350,7 +352,13 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType(FileUtilities.MIMETYPE_PDF); - intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, mDocumentUri); + // suggest directory and file name based on the doc + if (Build.VERSION.SDK_INT >= 26) { + intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, mDocumentUri); + } + final String displayName = toolbarTop.getTitle().toString(); + final String suggestedFileName = FileUtilities.stripExtensionFromFileName(displayName) + ".pdf"; + intent.putExtra(Intent.EXTRA_TITLE, suggestedFileName); startActivityForResult(intent, REQUEST_CODE_EXPORT_TO_PDF); } @@ -416,7 +424,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin } public void saveFileToOriginalSource() { - if (isReadOnlyMode() || mTempFile == null || mDocumentUri == null || !mDocumentUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) + if (mTempFile == null || mDocumentUri == null || !mDocumentUri.getScheme().equals(ContentResolver.SCHEME_CONTENT)) return; boolean copyOK = false; @@ -1085,25 +1093,14 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin } public void startPresentation(String tempPath) { - // pre-KitKat android doesn't have chrome-based WebView, which is needed to show svg slideshow - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - Intent intent = new Intent(this, PresentationActivity.class); - intent.setData(Uri.parse(tempPath)); - startActivity(intent); - } else { - // copy the svg file path to clipboard for the user to paste in a browser - ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText("temp svg file path", tempPath); - clipboard.setPrimaryClip(clip); - - AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage(R.string.alert_copy_svg_slide_show_to_clipboard) - .setPositiveButton(R.string.alert_copy_svg_slide_show_to_clipboard_dismiss, null).show(); - } + Intent intent = new Intent(this, PresentationActivity.class); + intent.setData(Uri.parse(tempPath)); + startActivity(intent); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_SAVEAS && resultCode == RESULT_OK) { final Uri fileUri = data.getData(); saveDocumentAs(fileUri); diff --git a/android/source/src/java/org/libreoffice/LocaleHelper.java b/android/source/src/java/org/libreoffice/LocaleHelper.java index 8c0e9b3fbbed..a87c63f09990 100644 --- a/android/source/src/java/org/libreoffice/LocaleHelper.java +++ b/android/source/src/java/org/libreoffice/LocaleHelper.java @@ -38,8 +38,7 @@ public class LocaleHelper { Resources res = context.getResources(); Configuration cfg = res.getConfiguration(); cfg.locale = locale; - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) - cfg.setLayoutDirection(locale); + cfg.setLayoutDirection(locale); res.updateConfiguration(cfg, res.getDisplayMetrics()); return context; diff --git a/android/source/src/java/org/libreoffice/PasswordDialogFragment.java b/android/source/src/java/org/libreoffice/PasswordDialogFragment.java index 112e35c4b7ed..08bc7f596894 100644 --- a/android/source/src/java/org/libreoffice/PasswordDialogFragment.java +++ b/android/source/src/java/org/libreoffice/PasswordDialogFragment.java @@ -4,9 +4,9 @@ import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.DialogFragment; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.DialogFragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/android/source/src/java/org/libreoffice/PresentationActivity.java b/android/source/src/java/org/libreoffice/PresentationActivity.java index 0fd3950f55d4..ede7c0c40101 100644 --- a/android/source/src/java/org/libreoffice/PresentationActivity.java +++ b/android/source/src/java/org/libreoffice/PresentationActivity.java @@ -1,16 +1,14 @@ package org.libreoffice; import android.content.Intent; -import android.os.Build; import android.os.Bundle; -import android.support.annotation.Nullable; -import android.support.v4.view.GestureDetectorCompat; -import android.support.v7.app.AppCompatActivity; +import androidx.annotation.Nullable; +import androidx.core.view.GestureDetectorCompat; +import androidx.appcompat.app.AppCompatActivity; import android.view.GestureDetector; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; -import android.view.WindowManager; import android.webkit.WebView; import android.widget.Button; import android.widget.ImageButton; diff --git a/android/source/src/java/org/libreoffice/SearchController.java b/android/source/src/java/org/libreoffice/SearchController.java index 8bdf42e8be8c..6095e1fd2afe 100644 --- a/android/source/src/java/org/libreoffice/SearchController.java +++ b/android/source/src/java/org/libreoffice/SearchController.java @@ -69,15 +69,8 @@ public class SearchController implements View.OnClickListener { ImageButton button = (ImageButton) view; SearchDirection direction = SearchDirection.DOWN; - switch(button.getId()) { - case R.id.button_search_down: - direction = SearchDirection.DOWN; - break; - case R.id.button_search_up: - direction = SearchDirection.UP; - break; - default: - break; + if (button.getId() == R.id.button_search_up) { + direction = SearchDirection.UP; } String searchText = ((EditText) mActivity.findViewById(R.id.search_string)).getText().toString(); diff --git a/android/source/src/java/org/libreoffice/ToolbarController.java b/android/source/src/java/org/libreoffice/ToolbarController.java index c97d84f0f329..603d2258167e 100644 --- a/android/source/src/java/org/libreoffice/ToolbarController.java +++ b/android/source/src/java/org/libreoffice/ToolbarController.java @@ -11,7 +11,7 @@ package org.libreoffice; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; -import android.support.v7.widget.Toolbar; +import androidx.appcompat.widget.Toolbar; import android.util.Log; import android.view.KeyEvent; import android.view.Menu; @@ -146,7 +146,7 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener { @Override public void run() { mMainMenu.setGroupVisible(R.id.group_edit_actions, false); - mToolbarTop.setNavigationIcon(R.drawable.lo_icon); + mToolbarTop.setNavigationIcon(R.mipmap.ic_launcher); mToolbarTop.setLogo(null); setEditModeOn(false); mContext.hideBottomToolbar(); @@ -162,85 +162,76 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener { @Override public boolean onMenuItemClick(MenuItem item) { - switch (item.getItemId()) { - case R.id.action_keyboard: - mContext.showSoftKeyboard(); - break; - case R.id.action_format: - mContext.showFormattingToolbar(); - break; - case R.id.action_about: - mContext.showAbout(); - return true; - case R.id.action_save: - mContext.getTileProvider().saveDocument(); - return true; - case R.id.action_save_as: - mContext.saveDocumentAs(); - return true; - case R.id.action_parts: - mContext.openDrawer(); - return true; - case R.id.action_exportToPDF: - mContext.exportToPDF(); - return true; - case R.id.action_print: - mContext.getTileProvider().printDocument(); - return true; - case R.id.action_settings: - mContext.showSettings(); - return true; - case R.id.action_search: - mContext.showSearchToolbar(); - return true; - case R.id.action_undo: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Undo")); - return true; - case R.id.action_redo: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Redo")); - return true; - case R.id.action_presentation: - mContext.preparePresentation(); - return true; - case R.id.action_add_slide: - mContext.addPart(); - return true; - case R.id.action_add_worksheet: - mContext.addPart(); - return true; - case R.id.action_rename_worksheet: - case R.id.action_rename_slide: - mContext.renamePart(); - return true; - case R.id.action_delete_worksheet: - mContext.deletePart(); - return true; - case R.id.action_delete_slide: - mContext.deletePart(); - return true; - case R.id.action_back: - hideClipboardActions(); - return true; - case R.id.action_copy: - LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Copy")); - clipData = ClipData.newPlainText("clipboard data", clipboardText); - clipboardManager.setPrimaryClip(clipData); - Toast.makeText(mContext, mContext.getResources().getString(R.string.action_text_copied), Toast.LENGTH_SHORT).show(); - return true; - case R.id.action_paste: - clipData = clipboardManager.getPrimaryClip(); - ClipData.Item clipItem = clipData.getItemAt(0); - mContext.setDocumentChanged(true); - return mContext.getTileProvider().paste("text/plain;charset=utf-16", clipItem.getText().toString()); - case R.id.action_cut: - clipData = ClipData.newPlainText("clipboard data", clipboardText); - clipboardManager.setPrimaryClip(clipData); - LOKitShell.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)); - mContext.setDocumentChanged(true); - return true; - case R.id.action_UNO_commands: - mContext.showUNOCommandsToolbar(); - return true; + final int itemId = item.getItemId(); + if (itemId == R.id.action_keyboard) { + mContext.showSoftKeyboard(); + } else if (itemId == R.id.action_format) { + mContext.showFormattingToolbar(); + } else if (itemId == R.id.action_about) { + mContext.showAbout(); + return true; + } else if (itemId == R.id.action_save) { + mContext.getTileProvider().saveDocument(); + return true; + } else if (itemId == R.id.action_save_as) { + mContext.saveDocumentAs(); + return true; + } else if (itemId == R.id.action_parts) { + mContext.openDrawer(); + return true; + } else if (itemId == R.id.action_exportToPDF) { + mContext.exportToPDF(); + return true; + } else if (itemId == R.id.action_print) { + mContext.getTileProvider().printDocument(); + return true; + } else if (itemId == R.id.action_settings) { + mContext.showSettings(); + return true; + } else if (itemId == R.id.action_search) { + mContext.showSearchToolbar(); + return true; + } else if (itemId == R.id.action_undo) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Undo")); + return true; + } else if (itemId == R.id.action_redo) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Redo")); + return true; + } else if (itemId == R.id.action_presentation) { + mContext.preparePresentation(); + return true; + } else if (itemId == R.id.action_add_slide || itemId == R.id.action_add_worksheet) { + mContext.addPart(); + return true; + } else if (itemId == R.id.action_rename_worksheet || itemId == R.id.action_rename_slide) { + mContext.renamePart(); + return true; + } else if (itemId == R.id.action_delete_worksheet || itemId == R.id.action_delete_slide) { + mContext.deletePart(); + return true; + } else if (itemId == R.id.action_back) { + hideClipboardActions(); + return true; + } else if (itemId == R.id.action_copy) { + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Copy")); + clipData = ClipData.newPlainText("clipboard data", clipboardText); + clipboardManager.setPrimaryClip(clipData); + Toast.makeText(mContext, mContext.getResources().getString(R.string.action_text_copied), Toast.LENGTH_SHORT).show(); + return true; + } else if (itemId == R.id.action_paste) { + clipData = clipboardManager.getPrimaryClip(); + ClipData.Item clipItem = clipData.getItemAt(0); + mContext.setDocumentChanged(true); + return mContext.getTileProvider().paste("text/plain;charset=utf-16", clipItem.getText().toString()); + } else if (itemId == R.id.action_cut) { + clipData = ClipData.newPlainText("clipboard data", clipboardText); + clipboardManager.setPrimaryClip(clipData); + LOKitShell.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)); + mContext.setDocumentChanged(true); + return true; + } else if (itemId == R.id.action_UNO_commands) { + mContext.showUNOCommandsToolbar(); + return true; } return false; } @@ -254,6 +245,8 @@ public class ToolbarController implements Toolbar.OnMenuItemClickListener { // but current document is readonly Toast.makeText(mContext, mContext.getString(R.string.readonly_file), Toast.LENGTH_LONG).show(); } + } else { + hideItem(R.id.action_save); } mMainMenu.findItem(R.id.action_parts).setVisible(mContext.isDrawerEnabled()); } diff --git a/android/source/src/java/org/libreoffice/UNOCommandsController.java b/android/source/src/java/org/libreoffice/UNOCommandsController.java index 5834f7e07001..cba67732cce1 100644 --- a/android/source/src/java/org/libreoffice/UNOCommandsController.java +++ b/android/source/src/java/org/libreoffice/UNOCommandsController.java @@ -8,7 +8,7 @@ package org.libreoffice; import android.content.DialogInterface; -import android.support.v7.app.AlertDialog; +import androidx.appcompat.app.AlertDialog; import android.text.method.ScrollingMovementMethod; import android.view.View; import android.widget.EditText; diff --git a/android/source/src/java/org/libreoffice/canvas/BitmapHandle.java b/android/source/src/java/org/libreoffice/canvas/BitmapHandle.java index e46173db518f..51f6f7cf8611 100644 --- a/android/source/src/java/org/libreoffice/canvas/BitmapHandle.java +++ b/android/source/src/java/org/libreoffice/canvas/BitmapHandle.java @@ -5,7 +5,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.RectF; import android.graphics.drawable.Drawable; -import android.support.v4.content.ContextCompat; +import androidx.core.content.ContextCompat; /** * Bitmap handle canvas element is used to show a handle on the screen. diff --git a/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java b/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java index c1f8e74e7ba2..a285234bc8b0 100644 --- a/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java +++ b/android/source/src/java/org/libreoffice/canvas/CalcHeaderCell.java @@ -4,29 +4,40 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Paint.Style; +import android.graphics.Rect; import android.graphics.RectF; import android.text.TextPaint; public class CalcHeaderCell extends CommonCanvasElement { - private TextPaint mTextPaint = new TextPaint(); - private Paint mBgPaint = new Paint(); - private RectF mBounds; - private String mText; + private final TextPaint mTextPaint = new TextPaint(); + + private final Paint mFramePaint = new Paint(); + private final Paint mBgPaint = new Paint(); + private final RectF mBounds; + private final Rect mTextBounds = new Rect(); + private final String mText; public CalcHeaderCell(float left, float top, float width, float height, String text, boolean selected) { mBounds = new RectF(left, top, left + width, top + height); + + mFramePaint.setStyle(Style.STROKE); + mFramePaint.setColor(Color.BLACK); + + mBgPaint.setStyle(Style.FILL); + mBgPaint.setColor(Color.GRAY); + // draw background more intensely when cell is selected if (selected) { - // if the cell is selected, display filled - mBgPaint.setStyle(Style.FILL_AND_STROKE); + mBgPaint.setAlpha(100); } else { - // if not, display only the frame - mBgPaint.setStyle(Style.STROKE); + mBgPaint.setAlpha(25); } - mBgPaint.setColor(Color.GRAY); - mBgPaint.setAlpha(100); // hard coded for now - mTextPaint.setColor(Color.GRAY); + + mTextPaint.setColor(Color.BLACK); mTextPaint.setTextSize(24f); // hard coded for now + mTextPaint.setTextAlign(Paint.Align.CENTER); mText = text; + + mTextPaint.getTextBounds(mText, 0, mText.length(), mTextBounds); } /** @@ -49,6 +60,7 @@ public class CalcHeaderCell extends CommonCanvasElement { @Override public void onDraw(Canvas canvas) { canvas.drawRect(mBounds, mBgPaint); - canvas.drawText(mText, mBounds.left, mBounds.bottom, mTextPaint); + canvas.drawRect(mBounds, mFramePaint); + canvas.drawText(mText, mBounds.centerX(), mBounds.centerY() - mTextBounds.centerY(), mTextPaint); } -}
\ No newline at end of file +} diff --git a/android/source/src/java/org/libreoffice/overlay/CalcHeadersController.java b/android/source/src/java/org/libreoffice/overlay/CalcHeadersController.java index 40c9ddcd8cea..8b99c292cbc5 100644 --- a/android/source/src/java/org/libreoffice/overlay/CalcHeadersController.java +++ b/android/source/src/java/org/libreoffice/overlay/CalcHeadersController.java @@ -4,7 +4,7 @@ import android.content.Context; import android.graphics.PointF; import android.graphics.RectF; import android.graphics.drawable.ColorDrawable; -import android.support.design.widget.Snackbar; +import com.google.android.material.snackbar.Snackbar; import android.util.Log; import android.view.KeyEvent; import android.view.Gravity; diff --git a/android/source/src/java/org/libreoffice/overlay/CalcHeadersView.java b/android/source/src/java/org/libreoffice/overlay/CalcHeadersView.java index a8b2d2048409..98af7a9554e7 100644 --- a/android/source/src/java/org/libreoffice/overlay/CalcHeadersView.java +++ b/android/source/src/java/org/libreoffice/overlay/CalcHeadersView.java @@ -4,7 +4,7 @@ import android.content.Context; import android.graphics.Canvas; import android.graphics.PointF; import android.graphics.RectF; -import android.support.v4.view.GestureDetectorCompat; +import androidx.core.view.GestureDetectorCompat; import android.util.AttributeSet; import android.view.GestureDetector.SimpleOnGestureListener; import android.view.MotionEvent; @@ -101,12 +101,8 @@ public class CalcHeadersView extends View { bottom = -origin.y + zoom*mDimens.get(i); if (top <= getHeight() && bottom >= 0) { inRangeOfVisibleHeaders = true; - if (mCellCursorRect != null && bottom > mCellCursorRect.top - origin.y && top < mCellCursorRect.bottom - origin.y) { - // if cell is within current selected portion - new CalcHeaderCell(0f, top, getWidth(), bottom - top, mLabels.get(i), true).onDraw(canvas); - } else { - new CalcHeaderCell(0f, top, getWidth(), bottom - top, mLabels.get(i), false).onDraw(canvas); - } + boolean isSelected = mCellCursorRect != null && bottom > mCellCursorRect.top - origin.y && top < mCellCursorRect.bottom - origin.y; + new CalcHeaderCell(0f, top, getWidth(), bottom - top, mLabels.get(i), isSelected).onDraw(canvas); } else { if (inRangeOfVisibleHeaders) { break; @@ -116,12 +112,8 @@ public class CalcHeadersView extends View { left = -origin.x + zoom*mDimens.get(i-1); right = -origin.x + zoom*mDimens.get(i); if (left <= getWidth() && right >= 0) { - if (mCellCursorRect != null && right > mCellCursorRect.left - origin.x && left < mCellCursorRect.right - origin.x) { - // if cell is within current selected portion - new CalcHeaderCell(left, 0f, right - left, getHeight(), mLabels.get(i), true).onDraw(canvas); - } else { - new CalcHeaderCell(left, 0f, right - left, getHeight(), mLabels.get(i), false).onDraw(canvas); - } + boolean isSelected = mCellCursorRect != null && right > mCellCursorRect.left - origin.x && left < mCellCursorRect.right - origin.x; + new CalcHeaderCell(left, 0f, right - left, getHeight(), mLabels.get(i), isSelected).onDraw(canvas); } else { if (inRangeOfVisibleHeaders) { break; diff --git a/android/source/src/java/org/libreoffice/ui/FileUtilities.java b/android/source/src/java/org/libreoffice/ui/FileUtilities.java index 5bfb93b4c1f5..7fc8c3c84eb1 100644 --- a/android/source/src/java/org/libreoffice/ui/FileUtilities.java +++ b/android/source/src/java/org/libreoffice/ui/FileUtilities.java @@ -63,7 +63,7 @@ public class FileUtilities { mExtnMap.put(".vsdx", DRAWING); mExtnMap.put(".pub", DRAWING); mExtnMap.put(".ppt", IMPRESS); - // mExtnMap.put(".pps", IMPRESS); + mExtnMap.put(".pps", IMPRESS); mExtnMap.put(".xls", CALC); // MS templates @@ -74,7 +74,7 @@ public class FileUtilities { // OOXML mExtnMap.put(".docx", DOC); mExtnMap.put(".pptx", IMPRESS); - // mExtnMap.put(".ppsx", IMPRESS); + mExtnMap.put(".ppsx", IMPRESS); mExtnMap.put(".xlsx", CALC); // OOXML templates @@ -124,6 +124,11 @@ public class FileUtilities { return mimeType != null && mimeType.endsWith("template"); } + public static String stripExtensionFromFileName(final String fileName) + { + return fileName.split("\\.[A-Za-z0-9]*$")[0]; + } + /** * Tries to retrieve the display (which should be the document name) * for the given URI using the given resolver. @@ -134,9 +139,9 @@ public class FileUtilities { Cursor cursor = null; try { String[] columns = {OpenableColumns.DISPLAY_NAME}; - cursor = resolver.query(docUri, columns, null, null); + cursor = resolver.query(docUri, columns, null, null, null); if (cursor != null && cursor.moveToFirst()) { - displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); + displayName = cursor.getString(cursor.getColumnIndexOrThrow(OpenableColumns.DISPLAY_NAME)); } } catch (SecurityException e) { // thrown e.g. when Uri has become invalid, e.g. corresponding file has been deleted diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java index 110123f54acf..bc5203d9c6eb 100644 --- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -23,15 +23,15 @@ import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; -import android.support.design.widget.FloatingActionButton; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; -import android.support.v4.view.ViewCompat; -import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.GridLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; +import com.google.android.material.floatingactionbutton.FloatingActionButton; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import androidx.core.view.ViewCompat; +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.GridLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import androidx.appcompat.widget.Toolbar; import android.text.TextUtils; import android.util.Log; import android.view.Menu; @@ -43,9 +43,9 @@ import android.view.animation.AnimationUtils; import android.view.animation.OvershootInterpolator; import android.widget.LinearLayout; import android.widget.TextView; -import android.widget.Toast; import org.libreoffice.AboutDialogFragment; +import org.libreoffice.BuildConfig; import org.libreoffice.LibreOfficeMainActivity; import org.libreoffice.LocaleHelper; import org.libreoffice.R; @@ -103,6 +103,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings "application/x-mspublisher", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/vnd.openxmlformats-officedocument.presentationml.presentation", + "application/vnd.openxmlformats-officedocument.presentationml.slideshow", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "application/vnd.openxmlformats-officedocument.wordprocessingml.template", "application/vnd.openxmlformats-officedocument.spreadsheetml.template", @@ -173,11 +174,16 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { - actionBar.setIcon(R.drawable.lo_icon); + actionBar.setIcon(R.mipmap.ic_launcher); } editFAB = findViewById(R.id.editFAB); editFAB.setOnClickListener(this); + // allow creating new docs only when experimental editing is enabled + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + final boolean bEditingEnabled = BuildConfig.ALLOW_EDITING && preferences.getBoolean(LibreOfficeMainActivity.ENABLE_EXPERIMENTAL_PREFS_KEY, false); + editFAB.setVisibility(bEditingEnabled ? View.VISIBLE : View.INVISIBLE); + impressFAB = findViewById(R.id.newImpressFAB); impressFAB.setOnClickListener(this); writerFAB = findViewById(R.id.newWriterFAB); @@ -190,7 +196,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings impressLayout = findViewById(R.id.impressLayout); calcLayout = findViewById(R.id.calcLayout); drawLayout = findViewById(R.id.drawLayout); - TextView openFileView = findViewById(R.id.open_file_view); + TextView openFileView = findViewById(R.id.open_file_button); openFileView.setOnClickListener(this); @@ -198,9 +204,9 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings SharedPreferences prefs = getSharedPreferences(EXPLORER_PREFS_KEY, MODE_PRIVATE); String recentPref = prefs.getString(RECENT_DOCUMENTS_KEY, ""); - List<String> recentFileStrings = Arrays.asList(recentPref.split(RECENT_DOCUMENTS_DELIMITER)); + String[] recentFileStrings = recentPref.split(RECENT_DOCUMENTS_DELIMITER); - final List<RecentFile> recentFiles = new ArrayList(); + final List<RecentFile> recentFiles = new ArrayList<>(); for (String recentFileString : recentFileStrings) { Uri uri = Uri.parse(recentFileString); String filename = FileUtilities.retrieveDisplayNameForDocumentUri(getContentResolver(), uri); @@ -250,6 +256,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE_OPEN_FILECHOOSER && resultCode == RESULT_OK) { final Uri fileUri = data.getData(); openDocument(fileUri); @@ -257,19 +264,14 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings } private void showSystemFilePickerAndOpenFile() { - Intent intent = new Intent(); - try { - intent.setAction(Intent.ACTION_OPEN_DOCUMENT); - } catch (ActivityNotFoundException exception) { - // Intent.ACTION_OPEN_DOCUMENT added in API level 19, but minSdkVersion is currently 16 - intent.setAction(Intent.ACTION_GET_CONTENT); - } - + Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); intent.setType("*/*"); - intent.putExtra(Intent.EXTRA_MIME_TYPES, SUPPORTED_MIME_TYPES);; + intent.putExtra(Intent.EXTRA_MIME_TYPES, SUPPORTED_MIME_TYPES); - if (intent.resolveActivity(getPackageManager()) != null) { + try { startActivityForResult(intent, REQUEST_CODE_OPEN_FILECHOOSER); + } catch (ActivityNotFoundException e) { + Log.w(LOGTAG, "No activity available that can handle the intent to open a document."); } } @@ -317,19 +319,18 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.action_about: { - AboutDialogFragment aboutDialogFragment = new AboutDialogFragment(); - aboutDialogFragment.show(getSupportFragmentManager(), "AboutDialogFragment"); - } - return true; - case R.id.action_settings: - startActivity(new Intent(getApplicationContext(), SettingsActivity.class)); - return true; - - default: - return super.onOptionsItemSelected(item); + final int itemId = item.getItemId(); + if (itemId == R.id.action_about) { + AboutDialogFragment aboutDialogFragment = new AboutDialogFragment(); + aboutDialogFragment.show(getSupportFragmentManager(), "AboutDialogFragment"); + return true; } + if (itemId == R.id.action_settings) { + startActivity(new Intent(getApplicationContext(), SettingsActivity.class)); + return true; + } + + return super.onOptionsItemSelected(item); } public void readPreferences(){ @@ -352,20 +353,13 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings private void addDocumentToRecents(Uri fileUri) { SharedPreferences prefs = getSharedPreferences(EXPLORER_PREFS_KEY, MODE_PRIVATE); - if (Build.VERSION.SDK_INT < 19) { - // ContentResolver#takePersistableUriPermission only available from SDK level 19 on - Log.i(LOGTAG, "Recently used files not supported, requires SDK version >= 19."); - // drop potential entries - prefs.edit().putString(RECENT_DOCUMENTS_KEY, "").apply(); - return; - } // preserve permissions across device reboots, // s. https://developer.android.com/training/data-storage/shared/documents-files#persist-permissions getContentResolver().takePersistableUriPermission(fileUri, Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); String newRecent = fileUri.toString(); - List<String> recentsList = new ArrayList(Arrays.asList(prefs.getString(RECENT_DOCUMENTS_KEY, "").split(RECENT_DOCUMENTS_DELIMITER))); + List<String> recentsList = new ArrayList<>(Arrays.asList(prefs.getString(RECENT_DOCUMENTS_KEY, "").split(RECENT_DOCUMENTS_DELIMITER))); // remove string if present, so that it doesn't appear multiple times recentsList.remove(newRecent); @@ -394,7 +388,7 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings //Remove all shortcuts, and apply new ones. shortcutManager.removeAllDynamicShortcuts(); - ArrayList<ShortcutInfo> shortcuts = new ArrayList<ShortcutInfo>(); + ArrayList<ShortcutInfo> shortcuts = new ArrayList<>(); for (String recentDoc : recentsList) { Uri docUri = Uri.parse(recentDoc); String filename = FileUtilities.retrieveDisplayNameForDocumentUri(getContentResolver(), docUri); @@ -440,35 +434,22 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings @Override public void onClick(View v) { int id = v.getId(); - switch (id){ - case R.id.editFAB: - // Intent.ACTION_CREATE_DOCUMENT, used in 'createNewFileDialog' requires SDK version 19 - if (Build.VERSION.SDK_INT < 19) { - Toast.makeText(this, - getString(R.string.creating_new_files_not_supported), Toast.LENGTH_SHORT).show(); - return; - } - if (isFabMenuOpen) { - collapseFabMenu(); - } else { - expandFabMenu(); - } - break; - case R.id.open_file_view: - showSystemFilePickerAndOpenFile(); - break; - case R.id.newWriterFAB: - loadNewDocument(DocumentType.WRITER); - break; - case R.id.newImpressFAB: - loadNewDocument(DocumentType.IMPRESS); - break; - case R.id.newCalcFAB: - loadNewDocument(DocumentType.CALC); - break; - case R.id.newDrawFAB: - loadNewDocument(DocumentType.DRAW); - break; + if (id == R.id.editFAB) { + if (isFabMenuOpen) { + collapseFabMenu(); + } else { + expandFabMenu(); + } + } else if (id == R.id.open_file_button) { + showSystemFilePickerAndOpenFile(); + } else if (id == R.id.newWriterFAB) { + loadNewDocument(DocumentType.WRITER); + } else if (id == R.id.newImpressFAB) { + loadNewDocument(DocumentType.IMPRESS); + } else if (id == R.id.newCalcFAB) { + loadNewDocument(DocumentType.CALC); + } else if (id == R.id.newDrawFAB) { + loadNewDocument(DocumentType.DRAW); } } } diff --git a/android/source/src/java/org/libreoffice/ui/PageView.java b/android/source/src/java/org/libreoffice/ui/PageView.java index 11b365f2bbcc..4c3f69562250 100644 --- a/android/source/src/java/org/libreoffice/ui/PageView.java +++ b/android/source/src/java/org/libreoffice/ui/PageView.java @@ -22,21 +22,21 @@ public class PageView extends View{ public PageView(Context context ) { super(context); bmp = BitmapFactory.decodeResource(getResources(), R.drawable.dummy_page); - intialise(); + initialise(); } public PageView(Context context, AttributeSet attrs) { super(context, attrs); bmp = BitmapFactory.decodeResource(getResources(), R.drawable.dummy_page); Log.d(LOGTAG, bmp.toString()); - intialise(); + initialise(); } public PageView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); bmp = BitmapFactory.decodeResource(getResources(), R.drawable.dummy_page);//load a "page" - intialise(); + initialise(); } - private void intialise(){ + private void initialise(){ mPaintBlack = new Paint(); mPaintBlack.setARGB(255, 0, 0, 0); Log.d(LOGTAG, " Doing some set-up"); diff --git a/android/source/src/java/org/libreoffice/ui/RecentFilesAdapter.java b/android/source/src/java/org/libreoffice/ui/RecentFilesAdapter.java index 6011035c1610..ef00b9fb6cfd 100644 --- a/android/source/src/java/org/libreoffice/ui/RecentFilesAdapter.java +++ b/android/source/src/java/org/libreoffice/ui/RecentFilesAdapter.java @@ -9,8 +9,8 @@ package org.libreoffice.ui; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.RecyclerView; +import androidx.core.content.ContextCompat; +import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; diff --git a/android/source/src/java/org/mozilla/gecko/ZoomConstraints.java b/android/source/src/java/org/mozilla/gecko/ZoomConstraints.java index f1672ba3dd76..dbe278827279 100644 --- a/android/source/src/java/org/mozilla/gecko/ZoomConstraints.java +++ b/android/source/src/java/org/mozilla/gecko/ZoomConstraints.java @@ -6,28 +6,16 @@ package org.mozilla.gecko; public final class ZoomConstraints { - private final boolean mAllowZoom; - private final boolean mAllowDoubleTapZoom; private final float mDefaultZoom; private final float mMinZoom; private final float mMaxZoom; - public ZoomConstraints(boolean allowZoom, float defaultZoom, float minZoom, float maxZoom) { - mAllowZoom = allowZoom; - mAllowDoubleTapZoom = allowZoom; + public ZoomConstraints(float defaultZoom, float minZoom, float maxZoom) { mDefaultZoom = defaultZoom; mMinZoom = minZoom; mMaxZoom = maxZoom; } - public final boolean getAllowZoom() { - return mAllowZoom; - } - - public final boolean getAllowDoubleTapZoom() { - return mAllowDoubleTapZoom; - } - public final float getDefaultZoom() { return mDefaultZoom; } diff --git a/android/source/src/java/org/mozilla/gecko/gfx/GLController.java b/android/source/src/java/org/mozilla/gecko/gfx/GLController.java index e296f4760f68..6a43dd6a87db 100644 --- a/android/source/src/java/org/mozilla/gecko/gfx/GLController.java +++ b/android/source/src/java/org/mozilla/gecko/gfx/GLController.java @@ -20,7 +20,6 @@ public class GLController { private LayerView mView; private int mGLVersion; - private boolean mSurfaceValid; private int mWidth, mHeight; private EGL10 mEGL; @@ -29,8 +28,6 @@ public class GLController { private EGLContext mEGLContext; private EGLSurface mEGLSurface; - private GL mGL; - private static final int LOCAL_EGL_OPENGL_ES2_BIT = 4; private static final int[] CONFIG_SPEC = { @@ -45,7 +42,6 @@ public class GLController { public GLController(LayerView view) { mView = view; mGLVersion = 2; - mSurfaceValid = false; } public void setGLVersion(int version) { @@ -84,12 +80,11 @@ public class GLController { getEGLError()); } - mGL = null; mEGLContext = null; } } - public GL getGL() { return mEGLContext.getGL(); } + public GL10 getGL() { return (GL10) mEGLContext.getGL(); } public EGLDisplay getEGLDisplay() { return mEGLDisplay; } public EGLConfig getEGLConfig() { return mEGLConfig; } public EGLContext getEGLContext() { return mEGLContext; } @@ -104,38 +99,6 @@ public class GLController { return mEGL.eglSwapBuffers(mEGLDisplay, mEGLSurface); } - public boolean checkForLostContext() { - if (mEGL.eglGetError() != EGL11.EGL_CONTEXT_LOST) { - return false; - } - - mEGLDisplay = null; - mEGLConfig = null; - mEGLContext = null; - mEGLSurface = null; - mGL = null; - return true; - } - - // This function is invoked by JNI - public synchronized void resumeCompositorIfValid() { - if (mSurfaceValid) { - mView.getListener().compositionResumeRequested(mWidth, mHeight); - } - } - - // Wait until we are allowed to use EGL functions on the Surface backing - // this window. This function is invoked by JNI - public synchronized void waitForValidSurface() { - while (!mSurfaceValid) { - try { - wait(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - } - public synchronized int getWidth() { return mWidth; } @@ -145,14 +108,12 @@ public class GLController { } synchronized void surfaceDestroyed() { - mSurfaceValid = false; notifyAll(); } synchronized void surfaceChanged(int newWidth, int newHeight) { mWidth = newWidth; mHeight = newHeight; - mSurfaceValid = true; notifyAll(); } @@ -183,11 +144,10 @@ public class GLController { getEGLError()); } - mGL = mEGLContext.getGL(); - if (mView.getRenderer() != null) { - mView.getRenderer().onSurfaceCreated((GL10)mGL, mEGLConfig); - mView.getRenderer().onSurfaceChanged((GL10)mGL, mWidth, mHeight); + GL10 gl = (GL10) mEGLContext.getGL(); + mView.getRenderer().onSurfaceCreated(gl, mEGLConfig); + mView.getRenderer().onSurfaceChanged(gl, mWidth, mHeight); } } @@ -216,7 +176,8 @@ public class GLController { } } - throw new GLControllerException("No suitable EGL configuration found"); + // if there's no 565 RGB configuration, select another one that fulfils the specification + return configs[0]; } private void createEGLSurface() { @@ -232,32 +193,11 @@ public class GLController { "surface! " + getEGLError()); } - mGL = mEGLContext.getGL(); - if (mView.getRenderer() != null) { - mView.getRenderer().onSurfaceCreated((GL10)mGL, mEGLConfig); - mView.getRenderer().onSurfaceChanged((GL10)mGL, mView.getWidth(), mView.getHeight()); - } - } - - /** - * Provides an EGLSurface without assuming ownership of this surface. - * This class does not keep a reference to the provided EGL surface; the - * caller assumes ownership of the surface once it is returned. - */ - private EGLSurface provideEGLSurface() { - if (mEGL == null) { - initEGL(); + GL10 gl = (GL10) mEGLContext.getGL(); + mView.getRenderer().onSurfaceCreated(gl, mEGLConfig); + mView.getRenderer().onSurfaceChanged(gl, mView.getWidth(), mView.getHeight()); } - - Object window = mView.getNativeWindow(); - EGLSurface surface = mEGL.eglCreateWindowSurface(mEGLDisplay, mEGLConfig, window, null); - if (surface == null || surface == EGL10.EGL_NO_SURFACE) { - throw new GLControllerException("EGL window surface could not be created! " + - getEGLError()); - } - - return surface; } private String getEGLError() { diff --git a/android/source/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java b/android/source/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java index db2fcc03c5b3..b20d602a21cb 100644 --- a/android/source/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java +++ b/android/source/src/java/org/mozilla/gecko/gfx/JavaPanZoomController.java @@ -21,6 +21,7 @@ import org.mozilla.gecko.util.FloatUtils; import java.util.Timer; import java.util.TimerTask; +import java.lang.StrictMath; /* * Handles the kinetic scrolling and zooming physics for a layer controller. @@ -143,16 +144,9 @@ class JavaPanZoomController /** This function MUST be called on the UI thread */ public boolean onMotionEvent(MotionEvent event) { - if (Build.VERSION.SDK_INT <= 11) { - return false; - } - - switch (event.getSource() & InputDevice.SOURCE_CLASS_MASK) { - case InputDevice.SOURCE_CLASS_POINTER: - switch (event.getAction() & MotionEvent.ACTION_MASK) { - case MotionEvent.ACTION_SCROLL: return handlePointerScroll(event); - } - break; + if ((event.getSource() & InputDevice.SOURCE_CLASS_MASK) == InputDevice.SOURCE_CLASS_POINTER + && (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_SCROLL) { + return handlePointerScroll(event); } return false; } @@ -433,7 +427,7 @@ class JavaPanZoomController private float panDistance(MotionEvent move) { float dx = mX.panDistance(move.getX(0)); float dy = mY.panDistance(move.getY(0)); - return (float) Math.sqrt(dx * dx + dy * dy); + return (float) Math.hypot(dx , dy); } private void track(float x, float y, long time) { @@ -550,7 +544,7 @@ class JavaPanZoomController private float getVelocity() { float xvel = mX.getRealVelocity(); float yvel = mY.getRealVelocity(); - return (float) Math.sqrt(xvel * xvel + yvel * yvel); + return (float) StrictMath.hypot(xvel, yvel); } public PointF getVelocityVector() { @@ -751,11 +745,6 @@ class JavaPanZoomController if (constraints.getMaxZoom() > 0) maxZoomFactor = constraints.getMaxZoom(); - if (!constraints.getAllowZoom()) { - // If allowZoom is false, clamp to the default zoom level. - maxZoomFactor = minZoomFactor = constraints.getDefaultZoom(); - } - maxZoomFactor = Math.max(maxZoomFactor, minZoomFactor); if (zoomFactor < minZoomFactor) { @@ -828,7 +817,7 @@ class JavaPanZoomController if (mState == PanZoomState.ANIMATED_ZOOM) return false; - if (null == mTarget.getZoomConstraints() || !mTarget.getZoomConstraints().getAllowZoom()) + if (null == mTarget.getZoomConstraints()) return false; setState(PanZoomState.PINCHING); @@ -934,10 +923,7 @@ class JavaPanZoomController @Override public boolean onDown(MotionEvent motionEvent) { - if (mTarget.getZoomConstraints() != null) - mWaitForDoubleTap = mTarget.getZoomConstraints().getAllowDoubleTapZoom(); - else - mWaitForDoubleTap = false; + mWaitForDoubleTap = mTarget.getZoomConstraints() != null; return false; } @@ -991,14 +977,14 @@ class JavaPanZoomController @Override public boolean onDoubleTap(MotionEvent motionEvent) { - if (null == mTarget.getZoomConstraints() || !mTarget.getZoomConstraints().getAllowDoubleTapZoom()) { + if (null == mTarget.getZoomConstraints()) { return true; } // Double tap zooms in or out depending on the current zoom factor PointF pointOfTap = getMotionInDocumentCoordinates(motionEvent); ImmutableViewportMetrics metrics = getMetrics(); float newZoom = metrics.getZoomFactor() >= - DOUBLE_TAP_THRESHOLD ? mTarget.getZoomConstraints().getMinZoom() : DOUBLE_TAP_THRESHOLD; + DOUBLE_TAP_THRESHOLD ? mTarget.getZoomConstraints().getDefaultZoom() : DOUBLE_TAP_THRESHOLD; // calculate new top_left point from the point of tap float ratio = newZoom/metrics.getZoomFactor(); float newLeft = pointOfTap.x - 1/ratio * (pointOfTap.x - metrics.getOrigin().x / metrics.getZoomFactor()); diff --git a/android/source/src/java/org/mozilla/gecko/gfx/LayerRenderer.java b/android/source/src/java/org/mozilla/gecko/gfx/LayerRenderer.java index b1aea3616d6c..6ea7dd0edc10 100644 --- a/android/source/src/java/org/mozilla/gecko/gfx/LayerRenderer.java +++ b/android/source/src/java/org/mozilla/gecko/gfx/LayerRenderer.java @@ -48,13 +48,9 @@ public class LayerRenderer implements GLSurfaceView.Renderer { private FloatBuffer mCoordBuffer; private RenderContext mLastPageContext; private int mMaxTextureSize; - private int mBackgroundColor; private CopyOnWriteArrayList<Layer> mExtraLayers = new CopyOnWriteArrayList<Layer>(); - /* Used by robocop for testing purposes */ - private IntBuffer mPixelBuffer; - // Used by GLES 2.0 private int mProgram; private int mPositionHandle; @@ -146,6 +142,7 @@ public class LayerRenderer implements GLSurfaceView.Renderer { mVertScrollLayer.destroy(); } + @Override public void onSurfaceCreated(GL10 gl, EGLConfig config) { createDefaultProgram(); activateDefaultProgram(); @@ -184,9 +181,6 @@ public class LayerRenderer implements GLSurfaceView.Renderer { GLES20.glEnableVertexAttribArray(mTextureHandle); GLES20.glUniform1i(mSampleHandle, 0); - - // TODO: Move these calls into a separate deactivate() call that is called after the - // underlay and overlay are rendered. } // Deactivates the shader program. This must be done to avoid crashes after returning to the @@ -220,8 +214,9 @@ public class LayerRenderer implements GLSurfaceView.Renderer { /** * Called whenever a new frame is about to be drawn. */ + @Override public void onDrawFrame(GL10 gl) { - Frame frame = createFrame(mView.getLayerClient().getViewportMetrics()); + Frame frame = new Frame(mView.getLayerClient().getViewportMetrics()); synchronized (mView.getLayerClient()) { frame.beginDrawing(); frame.drawBackground(); @@ -249,6 +244,7 @@ public class LayerRenderer implements GLSurfaceView.Renderer { mCoordBuffer); } + @Override public void onSurfaceChanged(GL10 gl, final int width, final int height) { GLES20.glViewport(0, 0, width, height); } @@ -264,10 +260,6 @@ public class LayerRenderer implements GLSurfaceView.Renderer { return shader; } - public Frame createFrame(ImmutableViewportMetrics metrics) { - return new Frame(metrics); - } - class FadeRunnable implements Runnable { private boolean mStarted; private long mRunAt; @@ -305,8 +297,6 @@ public class LayerRenderer implements GLSurfaceView.Renderer { } public class Frame { - // The timestamp recording the start of this frame. - private long mFrameStartTime; // A fixed snapshot of the viewport metrics that this frame is using to render content. private ImmutableViewportMetrics mFrameMetrics; // A rendering context for page-positioned layers, and one for screen-positioned layers. @@ -348,10 +338,7 @@ public class LayerRenderer implements GLSurfaceView.Renderer { return pageRect; } - /** This function is invoked via JNI; be careful when modifying signature. */ public void beginDrawing() { - mFrameStartTime = SystemClock.uptimeMillis(); - TextureReaper.get().reap(); TextureGenerator.get().fill(); @@ -386,58 +373,18 @@ public class LayerRenderer implements GLSurfaceView.Renderer { mUpdated &= layer.update(mPageContext); // called on compositor thread } - /** Retrieves the bounds for the layer, rounded in such a way that it - * can be used as a mask for something that will render underneath it. - * This will round the bounds inwards, but stretch the mask towards any - * near page edge, where near is considered to be 'within 2 pixels'. - * Returns null if the given layer is null. - */ - private Rect getMaskForLayer(Layer layer) { - if (layer == null) { - return null; - } - - RectF bounds = RectUtils.contract(layer.getBounds(mPageContext), 1.0f, 1.0f); - Rect mask = RectUtils.roundIn(bounds); - - // If the mask is within two pixels of any page edge, stretch it over - // that edge. This is to avoid drawing thin slivers when masking - // layers. - if (mask.top <= 2) { - mask.top = -1; - } - if (mask.left <= 2) { - mask.left = -1; - } - - // Because we're drawing relative to the page-rect, we only need to - // take into account its width and height (and not its origin) - int pageRight = mPageRect.width(); - int pageBottom = mPageRect.height(); - - if (mask.right >= pageRight - 2) { - mask.right = pageRight + 1; - } - if (mask.bottom >= pageBottom - 2) { - mask.bottom = pageBottom + 1; - } - - return mask; - } - - /** This function is invoked via JNI; be careful when modifying signature. */ public void drawBackground() { GLES20.glDisable(GLES20.GL_SCISSOR_TEST); /* Update background color. */ - mBackgroundColor = Color.WHITE; + final int backgroundColor = Color.WHITE; /* Clear to the page background colour. The bits set here need to * match up with those used in gfx/layers/opengl/LayerManagerOGL.cpp. */ - GLES20.glClearColor(((mBackgroundColor>>16)&0xFF) / 255.0f, - ((mBackgroundColor>>8)&0xFF) / 255.0f, - (mBackgroundColor&0xFF) / 255.0f, + GLES20.glClearColor(((backgroundColor >> 16) & 0xFF) / 255.0f, + ((backgroundColor >> 8) & 0xFF) / 255.0f, + (backgroundColor & 0xFF) / 255.0f, 0.0f); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT); @@ -474,7 +421,6 @@ public class LayerRenderer implements GLSurfaceView.Renderer { rootLayer.draw(mPageContext); } - /** This function is invoked via JNI; be careful when modifying signature. */ public void drawForeground() { /* Draw any extra layers that were added (likely plugins) */ if (mExtraLayers.size() > 0) { @@ -498,23 +444,10 @@ public class LayerRenderer implements GLSurfaceView.Renderer { mHorizScrollLayer.draw(mPageContext); } - /** This function is invoked via JNI; be careful when modifying signature. */ public void endDrawing() { // If a layer update requires further work, schedule another redraw if (!mUpdated) mView.requestRender(); - - /* Used by robocop for testing purposes */ - IntBuffer pixelBuffer = mPixelBuffer; - if (mUpdated && pixelBuffer != null) { - synchronized (pixelBuffer) { - pixelBuffer.position(0); - GLES20.glReadPixels(0, 0, (int)mScreenContext.viewport.width(), - (int)mScreenContext.viewport.height(), GLES20.GL_RGBA, - GLES20.GL_UNSIGNED_BYTE, pixelBuffer); - pixelBuffer.notify(); - } - } } } } diff --git a/android/source/src/java/org/mozilla/gecko/gfx/LayerView.java b/android/source/src/java/org/mozilla/gecko/gfx/LayerView.java index c9c5ca003297..29049f92912d 100644 --- a/android/source/src/java/org/mozilla/gecko/gfx/LayerView.java +++ b/android/source/src/java/org/mozilla/gecko/gfx/LayerView.java @@ -11,14 +11,12 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.PixelFormat; -import android.graphics.SurfaceTexture; import android.util.AttributeSet; import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.SurfaceHolder; import android.view.SurfaceView; -import android.view.TextureView; import android.view.View; import android.view.ViewGroup; import android.view.inputmethod.EditorInfo; @@ -37,8 +35,6 @@ import org.mozilla.gecko.OnSlideSwipeListener; * * This view delegates to LayerRenderer to actually do the drawing. Its role is largely that of a * mediator between the LayerRenderer and the LayerController. - * - * Note that LayerView is accessed by Robocop via reflection. */ public class LayerView extends FrameLayout { private static String LOGTAG = LayerView.class.getName(); @@ -49,59 +45,22 @@ public class LayerView extends FrameLayout { private InputConnectionHandler mInputConnectionHandler; private LayerRenderer mRenderer; - /* Must be a PAINT_xxx constant */ - private int mPaintState = PAINT_NONE; - private boolean mFullScreen = false; - private SurfaceView mSurfaceView; - private TextureView mTextureView; private Listener mListener; private OnInterceptTouchListener mTouchIntercepter; - //TODO static because of registerCxxCompositor() function, should be fixed in the future - private static LibreOfficeMainActivity mContext; - - /* Flags used to determine when to show the painted surface. The integer - * order must correspond to the order in which these states occur. */ - public static final int PAINT_NONE = 0; - public static final int PAINT_BEFORE_FIRST = 1; - public static final int PAINT_AFTER_FIRST = 2; - - boolean shouldUseTextureView() { - // we can only use TextureView on ICS or higher - /*if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) { - Log.i(LOGTAG, "Not using TextureView: not on ICS+"); - return false; - } - - try { - // and then we can only use it if we have a hardware accelerated window - Method m = View.class.getMethod("isHardwareAccelerated", new Class[0]); - return (Boolean) m.invoke(this); - } catch (Exception e) { - Log.i(LOGTAG, "Not using TextureView: caught exception checking for hw accel: " + e.toString()); - return false; - }*/ - return false; - } + private LibreOfficeMainActivity mContext; public LayerView(Context context, AttributeSet attrs) { super(context, attrs); mContext = (LibreOfficeMainActivity) context; - if (shouldUseTextureView()) { - mTextureView = new TextureView(context); - mTextureView.setSurfaceTextureListener(new SurfaceTextureListener()); - - addView(mTextureView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); - } else { - mSurfaceView = new SurfaceView(context); - addView(mSurfaceView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + mSurfaceView = new SurfaceView(context); + addView(mSurfaceView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); - SurfaceHolder holder = mSurfaceView.getHolder(); - holder.addCallback(new SurfaceListener()); + SurfaceHolder holder = mSurfaceView.getHolder(); + holder.addCallback(new SurfaceListener()); holder.setFormat(PixelFormat.RGB_565); - } mGLController = new GLController(this); } @@ -219,13 +178,6 @@ public class LayerView extends FrameLayout { return mInputConnectionHandler != null && mInputConnectionHandler.onKeyUp(keyCode, event); } - public boolean isIMEEnabled() { - /*if (mInputConnectionHandler != null) { - return mInputConnectionHandler.isIMEEnabled(); - }*/ - return false; - } - public void requestRender() { if (mListener != null) { mListener.renderRequested(); @@ -252,19 +204,6 @@ public class LayerView extends FrameLayout { return mRenderer; } - /* paintState must be a PAINT_xxx constant. The state will only be changed - * if paintState represents a state that occurs after the current state. */ - public void setPaintState(int paintState) { - if (paintState > mPaintState) { - Log.d(LOGTAG, "LayerView paint state set to " + paintState); - mPaintState = paintState; - } - } - - public int getPaintState() { - return mPaintState; - } - public LayerRenderer getRenderer() { return mRenderer; } @@ -320,29 +259,13 @@ public class LayerView extends FrameLayout { } public Object getNativeWindow() { - if (mSurfaceView != null) - return mSurfaceView.getHolder(); - - return mTextureView.getSurfaceTexture(); - } - - /** This function is invoked by Gecko (compositor thread) via JNI; be careful when modifying signature. */ - public static GLController registerCxxCompositor() { - try { - LayerView layerView = mContext.getLayerClient().getView(); - layerView.mListener.compositorCreated(); - return layerView.getGLController(); - } catch (Exception e) { - Log.e(LOGTAG, "Error registering compositor!", e); - return null; - } + return mSurfaceView.getHolder(); } public interface Listener { void compositorCreated(); void renderRequested(); void compositionPauseRequested(); - void compositionResumeRequested(int width, int height); void surfaceChanged(int width, int height); } @@ -371,29 +294,6 @@ public class LayerView extends FrameLayout { } } - private class SurfaceTextureListener implements TextureView.SurfaceTextureListener { - public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) { - // We don't do this for surfaceCreated above because it is always followed by a surfaceChanged, - // but that is not the case here. - if (mRenderControllerThread != null) { - mRenderControllerThread.surfaceCreated(); - } - onSizeChanged(width, height); - } - - public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) { - onDestroyed(); - return true; // allow Android to call release() on the SurfaceTexture, we are done drawing to it - } - - public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) { - onSizeChanged(width, height); - } - - public void onSurfaceTextureUpdated(SurfaceTexture surface) { - } - } - private RenderControllerThread mRenderControllerThread; public synchronized void createGLThread() { @@ -434,12 +334,4 @@ public class LayerView extends FrameLayout { super(e); } } - - public void setFullScreen(boolean fullScreen) { - mFullScreen = fullScreen; - } - - public boolean isFullScreen() { - return mFullScreen; - } } diff --git a/android/source/src/java/org/mozilla/gecko/gfx/PointUtils.java b/android/source/src/java/org/mozilla/gecko/gfx/PointUtils.java index 4eb07a31f147..4eff380527d2 100644 --- a/android/source/src/java/org/mozilla/gecko/gfx/PointUtils.java +++ b/android/source/src/java/org/mozilla/gecko/gfx/PointUtils.java @@ -11,6 +11,8 @@ import android.graphics.PointF; import org.json.JSONException; import org.json.JSONObject; +import java.lang.StrictMath; + public final class PointUtils { public static PointF add(PointF one, PointF two) { return new PointF(one.x + two.x, one.y + two.y); @@ -30,7 +32,7 @@ public final class PointUtils { /* Computes the magnitude of the given vector. */ public static float distance(PointF point) { - return (float)Math.sqrt(point.x * point.x + point.y * point.y); + return (float)StrictMath.hypot(point.x, point.y); } /** Computes the scalar distance between two points. */ diff --git a/android/source/src/java/org/mozilla/gecko/gfx/RenderControllerThread.java b/android/source/src/java/org/mozilla/gecko/gfx/RenderControllerThread.java index 06f82f158366..5c74d56a004b 100644 --- a/android/source/src/java/org/mozilla/gecko/gfx/RenderControllerThread.java +++ b/android/source/src/java/org/mozilla/gecko/gfx/RenderControllerThread.java @@ -82,11 +82,6 @@ public class RenderControllerThread extends Thread implements LayerView.Listener } @Override - public void compositionResumeRequested(int width, int height) { - - } - - @Override public void surfaceChanged(int width, int height) { this.width = width; this.height = height; @@ -115,7 +110,7 @@ public class RenderControllerThread extends Thread implements LayerView.Listener } GLSurfaceView.Renderer renderer = getRenderer(); if (renderer != null) { - renderer.onDrawFrame((GL10) controller.getGL()); + renderer.onDrawFrame(controller.getGL()); } controller.swapBuffers(); } @@ -123,7 +118,7 @@ public class RenderControllerThread extends Thread implements LayerView.Listener private void doSizeChanged() { GLSurfaceView.Renderer renderer = getRenderer(); if (renderer != null) { - renderer.onSurfaceChanged((GL10) controller.getGL(), width, height); + renderer.onSurfaceChanged(controller.getGL(), width, height); } } diff --git a/android/source/src/java/org/mozilla/gecko/gfx/SimpleScaleGestureDetector.java b/android/source/src/java/org/mozilla/gecko/gfx/SimpleScaleGestureDetector.java index 1d901a02a14b..e89015b5ed8c 100644 --- a/android/source/src/java/org/mozilla/gecko/gfx/SimpleScaleGestureDetector.java +++ b/android/source/src/java/org/mozilla/gecko/gfx/SimpleScaleGestureDetector.java @@ -34,7 +34,7 @@ import java.util.Stack; * - It doesn't take pressure into account, which results in smoother scaling. */ public class SimpleScaleGestureDetector { - private static final String LOGTAG = "GeckoSimpleScaleGestureDetector"; + private static final String LOGTAG = "ScaleGestureDetector"; private SimpleScaleGestureListener mListener; private long mLastEventTime; |