android/source/res/layout/activity_main.xml | 3 android/source/res/layout/toolbar_bottom.xml | 28 ++ android/source/res/layout/toolbar_color_picker.xml | 1 android/source/src/java/org/libreoffice/FontController.java | 138 +++++++++- android/source/src/java/org/libreoffice/InvalidationHandler.java | 2 android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java | 6 6 files changed, 166 insertions(+), 12 deletions(-)
New commits: commit 3deac9691011711a3b9e50d19499c588af074d7f Author: Mert Tümer <merttum...@gmail.com> Date: Sun Jan 21 19:10:10 2018 +0300 [Pardus] tdf#106326 ability to change font background color This patch is sponsored by ULAKBIM/PARDUS project. Signed-off-by: Mert Tümer <merttum...@gmail.com> Change-Id: I4dfbb9e35214e4d4a9aa6dca1ce3d5d2604218a9 Reviewed-on: https://gerrit.libreoffice.org/48270 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Thorsten Behrens <thorsten.behr...@cib.de> diff --git a/android/source/res/layout/activity_main.xml b/android/source/res/layout/activity_main.xml index 9f53b4f5d3dd..c2528023d0f8 100644 --- a/android/source/res/layout/activity_main.xml +++ b/android/source/res/layout/activity_main.xml @@ -110,7 +110,8 @@ </LinearLayout> <include layout="@layout/toolbar_bottom"/> - <include layout="@layout/toolbar_color_picker"/> + <include android:id="@+id/toolbar_back_color_picker" layout="@layout/toolbar_color_picker"/> + <include android:id="@+id/toolbar_color_picker" layout="@layout/toolbar_color_picker"/> <RelativeLayout android:id="@+id/loadingPanel" diff --git a/android/source/res/layout/toolbar_bottom.xml b/android/source/res/layout/toolbar_bottom.xml index a537a52d32b9..d944b2713f2a 100644 --- a/android/source/res/layout/toolbar_bottom.xml +++ b/android/source/res/layout/toolbar_bottom.xml @@ -197,6 +197,34 @@ /> </RelativeLayout> + <RelativeLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:id="@+id/font_back_color_picker" + android:padding="10dp"> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Font Back Color" + android:paddingBottom="12dp" + android:paddingTop="12dp" + android:textSize="14sp" + android:gravity="center_vertical" + android:textColor="@color/fontBlack" + android:layout_alignParentLeft="true" + + /> + <ImageButton + android:id="@+id/font_back_color_picker_button" + android:layout_width="24dp" + android:layout_height="24dp" + android:gravity="center_vertical" + android:paddingBottom="12dp" + android:paddingTop="12dp" + android:layout_alignParentRight="true" + /> + + </RelativeLayout> </LinearLayout> </ScrollView> diff --git a/android/source/res/layout/toolbar_color_picker.xml b/android/source/res/layout/toolbar_color_picker.xml index e34b6c6a5d72..9393259123be 100644 --- a/android/source/res/layout/toolbar_color_picker.xml +++ b/android/source/res/layout/toolbar_color_picker.xml @@ -3,7 +3,6 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" - android:id="@+id/toolbar_color_picker" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" diff --git a/android/source/src/java/org/libreoffice/FontController.java b/android/source/src/java/org/libreoffice/FontController.java index db87302cbd4a..04fc6ccaa234 100644 --- a/android/source/src/java/org/libreoffice/FontController.java +++ b/android/source/src/java/org/libreoffice/FontController.java @@ -28,7 +28,7 @@ public class FontController implements AdapterView.OnItemSelectedListener { private boolean mFontNameSpinnerSet = false; private boolean mFontSizeSpinnerSet = false; - private Activity mActivity; + private LibreOfficeMainActivity mActivity; private List<String> mFontList = null; private List<String> mFontSizes = new ArrayList<String>(); private Map<String, List<String>> mAllFontSizes = null; @@ -36,12 +36,14 @@ public class FontController implements AdapterView.OnItemSelectedListener { private String mCurrentFontSelected = null; private String mCurrentFontSizeSelected = null; - public FontController(Activity activity) { + public FontController(LibreOfficeMainActivity activity) { mActivity = activity; } private BottomSheetBehavior colorPickerBehavior; + private BottomSheetBehavior backColorPickerBehavior; private BottomSheetBehavior toolBarBottomBehavior; private ColorPickerAdapter colorPickerAdapter; + private ColorPickerAdapter backColorPickerAdapter; ColorPaletteListener colorPaletteListener = new ColorPaletteListener() { @Override @@ -52,8 +54,22 @@ public class FontController implements AdapterView.OnItemSelectedListener { @Override public void updateColorPickerPosition(int color) { if (null == colorPickerAdapter) return; - colorPickerAdapter.findSelectedTextColor(color); - changeFontColorBoxColor(color); + colorPickerAdapter.findSelectedTextColor(color + 0xFF000000); + changeFontColorBoxColor(color + 0xFF000000); + } + }; + + ColorPaletteListener backColorPaletteListener = new ColorPaletteListener() { + @Override + public void applyColor(int color) { + sendFontBackColorChange(color); + } + + @Override + public void updateColorPickerPosition(int color) { + backColorPickerAdapter.findSelectedTextColor(color + 0xFF000000); + changeFontBackColorBoxColor(color + 0xFF000000); + } }; @@ -67,11 +83,27 @@ public class FontController implements AdapterView.OnItemSelectedListener { fontColorPickerButton.setBackgroundColor(Color.BLACK); }else{ fontColorPickerButton.setBackgroundColor(color); + } + } + }); + } + + private void changeFontBackColorBoxColor(final int color){ + final ImageButton fontBackColorPickerButton = mActivity.findViewById(R.id.font_back_color_picker_button); + + 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); } } }); } + private void sendFontChange(String fontName) { try { JSONObject json = new JSONObject(); @@ -107,7 +139,7 @@ public class FontController implements AdapterView.OnItemSelectedListener { JSONObject json = new JSONObject(); JSONObject valueJson = new JSONObject(); valueJson.put("type", "long"); - valueJson.put("value", color); + valueJson.put("value", 0x00FFFFFF & color); json.put("Color", valueJson); LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:Color", json.toString())); @@ -118,6 +150,31 @@ public class FontController implements AdapterView.OnItemSelectedListener { } } + /* + * 0x00FFFFFF & color operation removes the alpha which is FF, + * if we dont remove it, the color value becomes negative which is not recognized by LOK + */ + private void sendFontBackColorChange(int color){ + try { + JSONObject json = new JSONObject(); + JSONObject valueJson = new JSONObject(); + valueJson.put("type", "long"); + valueJson.put("value", 0x00FFFFFF & color); + if(mActivity.isSpreadsheet()){ + json.put("BackgroundColor", valueJson); + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:BackgroundColor", json.toString())); + } else { + json.put("BackColor", valueJson); + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:BackColor", json.toString())); + } + + changeFontBackColorBoxColor(color); + + } catch (JSONException e) { + e.printStackTrace(); + } + } + @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { @@ -172,6 +229,7 @@ public class FontController implements AdapterView.OnItemSelectedListener { setupFontNameSpinner(); setupFontSizeSpinner(); setupColorPicker(); + setupBackColorPicker(); } }); } @@ -191,14 +249,16 @@ public class FontController implements AdapterView.OnItemSelectedListener { } private void setupColorPicker(){ - RecyclerView recyclerView = mActivity.findViewById(R.id.fontColorView); + LinearLayout colorPickerLayout = (LinearLayout)mActivity.findViewById(R.id.toolbar_color_picker); + + RecyclerView recyclerView = colorPickerLayout.findViewById(R.id.fontColorView); GridLayoutManager gridLayoutManager = new GridLayoutManager(mActivity, 11, GridLayoutManager.VERTICAL, true); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(gridLayoutManager); - RecyclerView recyclerView2 = mActivity.findViewById(R.id.fontColorViewSub); + RecyclerView recyclerView2 = colorPickerLayout.findViewById(R.id.fontColorViewSub); GridLayoutManager gridLayoutManager2 = new GridLayoutManager(mActivity,4); recyclerView2.setHasFixedSize(true); recyclerView2.addItemDecoration(new RecyclerView.ItemDecoration() { @@ -228,12 +288,11 @@ public class FontController implements AdapterView.OnItemSelectedListener { mActivity.findViewById(R.id.search_toolbar).setVisibility(View.GONE); } }; - LinearLayout toolbarColorPicker = mActivity.findViewById(R.id.toolbar_color_picker); LinearLayout toolbarBottomLayout = mActivity.findViewById(R.id.toolbar_bottom); - colorPickerBehavior = BottomSheetBehavior.from(toolbarColorPicker); + colorPickerBehavior = BottomSheetBehavior.from(colorPickerLayout); toolBarBottomBehavior = BottomSheetBehavior.from(toolbarBottomLayout); - ImageButton pickerGoBackButton = mActivity.findViewById(R.id.button_go_back_color_picker); + ImageButton pickerGoBackButton = colorPickerLayout.findViewById(R.id.button_go_back_color_picker); pickerGoBackButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -248,6 +307,65 @@ public class FontController implements AdapterView.OnItemSelectedListener { } + private void setupBackColorPicker(){ + LinearLayout backColorPickerLayout = mActivity.findViewById(R.id.toolbar_back_color_picker); + + RecyclerView recyclerView = backColorPickerLayout.findViewById(R.id.fontColorView); + GridLayoutManager gridLayoutManager = new GridLayoutManager(mActivity, 11, GridLayoutManager.VERTICAL, true); + recyclerView.setHasFixedSize(true); + recyclerView.setLayoutManager(gridLayoutManager); + + + + RecyclerView recyclerView2 = backColorPickerLayout.findViewById(R.id.fontColorViewSub); + GridLayoutManager gridLayoutManager2 = new GridLayoutManager(mActivity,4); + recyclerView2.setHasFixedSize(true); + recyclerView2.addItemDecoration(new RecyclerView.ItemDecoration() { + + @Override + public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { + outRect.bottom = 3; + outRect.top = 3; + outRect.left = 3; + outRect.right = 3; + } + }); + recyclerView2.setLayoutManager(gridLayoutManager2); + + ColorPaletteAdapter colorPaletteAdapter = new ColorPaletteAdapter(mActivity, backColorPaletteListener); + recyclerView2.setAdapter(colorPaletteAdapter); + + this.backColorPickerAdapter = new ColorPickerAdapter(mActivity, colorPaletteAdapter, backColorPaletteListener); + recyclerView.setAdapter(backColorPickerAdapter); + RelativeLayout fontColorPicker = mActivity.findViewById(R.id.font_back_color_picker); + ImageButton fontColorPickerButton = mActivity.findViewById(R.id.font_back_color_picker_button); + View.OnClickListener clickListener = new View.OnClickListener(){ + @Override + public void onClick(View view) { + toolBarBottomBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); + backColorPickerBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); + mActivity.findViewById(R.id.search_toolbar).setVisibility(View.GONE); + } + }; + LinearLayout toolbarBottomLayout = mActivity.findViewById(R.id.toolbar_bottom); + backColorPickerBehavior = BottomSheetBehavior.from(backColorPickerLayout); + toolBarBottomBehavior = BottomSheetBehavior.from(toolbarBottomLayout); + + ImageButton pickerGoBackButton = backColorPickerLayout.findViewById(R.id.button_go_back_color_picker); + pickerGoBackButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + toolBarBottomBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); + backColorPickerBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); + } + }); + + + fontColorPicker.setOnClickListener(clickListener); + fontColorPickerButton.setOnClickListener(clickListener); + + } + public void selectFont(final String fontName) { LOKitShell.getMainHandler().post(new Runnable() { public void run() { diff --git a/android/source/src/java/org/libreoffice/InvalidationHandler.java b/android/source/src/java/org/libreoffice/InvalidationHandler.java index a79ecde2ad01..5dcb572af6c4 100644 --- a/android/source/src/java/org/libreoffice/InvalidationHandler.java +++ b/android/source/src/java/org/libreoffice/InvalidationHandler.java @@ -269,6 +269,8 @@ 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 (parts[0].equals(".uno:BackColor")) { + mContext.getFontController().backColorPaletteListener.updateColorPickerPosition(Integer.parseInt(value)); } else if (parts[0].equals(".uno:StatePageNumber")) { // get the total page number and compare to the current value and update accordingly String[] splitStrings = parts[1].split(" "); diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java index 91722fa98d35..a7a13c45c9a4 100644 --- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -89,6 +89,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin BottomSheetBehavior bottomToolbarSheetBehavior; BottomSheetBehavior toolbarColorPickerBottomSheetBehavior; + BottomSheetBehavior toolbarBackColorPickerBottomSheetBehavior; private FormattingController mFormattingController; private ToolbarController mToolbarController; private FontController mFontController; @@ -237,10 +238,13 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin LinearLayout bottomToolbarLayout = findViewById(R.id.toolbar_bottom); LinearLayout toolbarColorPickerLayout = findViewById(R.id.toolbar_color_picker); + LinearLayout toolbarBackColorPickerLayout = findViewById(R.id.toolbar_back_color_picker); bottomToolbarSheetBehavior = BottomSheetBehavior.from(bottomToolbarLayout); toolbarColorPickerBottomSheetBehavior = BottomSheetBehavior.from(toolbarColorPickerLayout); + toolbarBackColorPickerBottomSheetBehavior = BottomSheetBehavior.from(toolbarBackColorPickerLayout); bottomToolbarSheetBehavior.setHideable(true); toolbarColorPickerBottomSheetBehavior.setHideable(true); + toolbarBackColorPickerBottomSheetBehavior.setHideable(true); } // Loads a new Document @@ -568,6 +572,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin public void run() { bottomToolbarSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); toolbarColorPickerBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); + toolbarBackColorPickerBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); findViewById(R.id.search_toolbar).setVisibility(View.GONE); isFormattingToolbarOpen=false; isSearchToolbarOpen=false; @@ -613,6 +618,7 @@ public class LibreOfficeMainActivity extends AppCompatActivity implements Settin showBottomToolbar(); findViewById(R.id.formatting_toolbar).setVisibility(View.GONE); toolbarColorPickerBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); + toolbarBackColorPickerBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED); findViewById(R.id.search_toolbar).setVisibility(View.VISIBLE); hideSoftKeyboardDirect(); isFormattingToolbarOpen=false; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits