diff options
author | Mert Tümer <merttumer7@gmail.com> | 2018-05-25 15:15:29 +0300 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2018-06-01 04:30:20 +0200 |
commit | ea62d02cedd7b6c90ebcb0ce73e30dc6ddd342c8 (patch) | |
tree | 43d2dec03a8c33ae785c31755639b5af8d810ff5 /android | |
parent | 22ef830aa01bfe1e74d649d3ad01ece29a72c44d (diff) |
[Pardus] tdf#106371 ability to insert/delete tables Android Viewer
This patch is sponsored by ULAKBIM/PARDUS project.
Signed-off-by: Mert Tümer <merttumer7@gmail.com>
Change-Id: I2d160b53ad432be96deb6f13c0d91a6053744dc8
Reviewed-on: https://gerrit.libreoffice.org/54803
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'android')
-rw-r--r-- | android/source/res/drawable/ic_grid_off_black_24dp.xml | 9 | ||||
-rw-r--r-- | android/source/res/drawable/ic_grid_on_black_24dp.xml | 9 | ||||
-rw-r--r-- | android/source/res/layout/number_picker.xml | 130 | ||||
-rw-r--r-- | android/source/res/layout/toolbar_bottom.xml | 20 | ||||
-rw-r--r-- | android/source/res/values/strings.xml | 16 | ||||
-rw-r--r-- | android/source/src/java/org/libreoffice/FormattingController.java | 164 |
6 files changed, 348 insertions, 0 deletions
diff --git a/android/source/res/drawable/ic_grid_off_black_24dp.xml b/android/source/res/drawable/ic_grid_off_black_24dp.xml new file mode 100644 index 000000000000..7cf3c950cc4b --- /dev/null +++ b/android/source/res/drawable/ic_grid_off_black_24dp.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + <path + android:fillColor="#FF000000" + android:pathData="M8,4v1.45l2,2L10,4h4v4h-3.45l2,2L14,10v1.45l2,2L16,10h4v4h-3.45l2,2L20,16v1.45l2,2L22,4c0,-1.1 -0.9,-2 -2,-2L4.55,2l2,2L8,4zM16,4h4v4h-4L16,4zM1.27,1.27L0,2.55l2,2L2,20c0,1.1 0.9,2 2,2h15.46l2,2 1.27,-1.27L1.27,1.27zM10,12.55L11.45,14L10,14v-1.45zM4,6.55L5.45,8L4,8L4,6.55zM8,20L4,20v-4h4v4zM8,14L4,14v-4h3.45l0.55,0.55L8,14zM14,20h-4v-4h3.45l0.55,0.54L14,20zM16,20v-1.46L17.46,20L16,20z"/> +</vector> diff --git a/android/source/res/drawable/ic_grid_on_black_24dp.xml b/android/source/res/drawable/ic_grid_on_black_24dp.xml new file mode 100644 index 000000000000..b2ff9e5be07b --- /dev/null +++ b/android/source/res/drawable/ic_grid_on_black_24dp.xml @@ -0,0 +1,9 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + <path + android:fillColor="#FF000000" + android:pathData="M20,2L4,2c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM8,20L4,20v-4h4v4zM8,14L4,14v-4h4v4zM8,8L4,8L4,4h4v4zM14,20h-4v-4h4v4zM14,14h-4v-4h4v4zM14,8h-4L10,4h4v4zM20,20h-4v-4h4v4zM20,14h-4v-4h4v4zM20,8h-4L16,4h4v4z"/> +</vector> diff --git a/android/source/res/layout/number_picker.xml b/android/source/res/layout/number_picker.xml new file mode 100644 index 000000000000..51463926c70f --- /dev/null +++ b/android/source/res/layout/number_picker.xml @@ -0,0 +1,130 @@ +<?xml version="1.0" encoding="utf-8"?> +<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:padding="15dp" + android:id="@+id/numberpickerLayout"> + + <TextView + android:id="@+id/textView11" + android:layout_width="wrap_content" + android:layout_height="30dp" + android:layout_marginStart="8dp" + android:layout_marginLeft="8dp" + android:layout_marginTop="8dp" + android:text="Rows:" + android:gravity="center" + android:textSize="18sp" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + + <TextView + android:id="@+id/number_picker_rows_positive" + android:layout_width="30dp" + android:layout_height="30dp" + android:layout_marginEnd="8dp" + android:layout_marginRight="8dp" + android:layout_marginTop="8dp" + android:background="@drawable/image_button_background" + android:clickable="true" + android:gravity="center" + android:text="+" + android:textSize="18sp" + android:textStyle="bold" + app:layout_constraintEnd_toEndOf="@+id/numberpickerLayout" + app:layout_constraintTop_toTopOf="@+id/numberpickerLayout" /> + + <TextView + android:id="@+id/number_picker_row_count" + android:layout_width="30dp" + android:layout_height="30dp" + android:layout_marginEnd="8dp" + android:layout_marginStart="8dp" + android:layout_marginTop="8dp" + android:text="3" + android:gravity="center" + android:textSize="18sp" + android:textStyle="bold" + app:layout_constraintEnd_toStartOf="@+id/number_picker_rows_positive" + app:layout_constraintStart_toEndOf="@+id/number_picker_rows_negative" + app:layout_constraintTop_toTopOf="@+id/numberpickerLayout" /> + + <TextView + android:id="@+id/number_picker_rows_negative" + android:layout_width="30dp" + android:layout_height="30dp" + android:layout_marginEnd="8dp" + android:layout_marginStart="8dp" + android:layout_marginTop="8dp" + android:text="-" + android:gravity="center" + android:textSize="18sp" + android:textStyle="bold" + android:clickable="true" + android:background="@drawable/image_button_background" + app:layout_constraintEnd_toEndOf="@+id/numberpickerLayout" + app:layout_constraintStart_toStartOf="@+id/numberpickerLayout" + app:layout_constraintTop_toTopOf="@+id/numberpickerLayout" /> + + <TextView + android:id="@+id/textView12" + android:layout_width="wrap_content" + android:layout_height="30dp" + android:layout_marginStart="8dp" + android:layout_marginLeft="8dp" + android:layout_marginTop="24dp" + android:text="Columns:" + android:gravity="center" + android:textSize="18sp" + app:layout_constraintStart_toStartOf="@+id/numberpickerLayout" + app:layout_constraintTop_toBottomOf="@+id/textView11" /> + + <TextView + android:id="@+id/number_picker_cols_negative" + android:layout_width="30dp" + android:layout_height="30dp" + android:layout_marginEnd="8dp" + android:layout_marginStart="8dp" + android:layout_marginTop="24dp" + android:text="-" + android:gravity="center" + android:textSize="18sp" + android:textStyle="bold" + android:background="@drawable/image_button_background" + android:clickable="true" + app:layout_constraintEnd_toEndOf="@+id/numberpickerLayout" + app:layout_constraintStart_toStartOf="@+id/numberpickerLayout" + app:layout_constraintTop_toBottomOf="@+id/number_picker_rows_negative" /> + + <TextView + android:id="@+id/number_picker_col_count" + android:layout_width="30dp" + android:layout_height="30dp" + android:layout_marginEnd="8dp" + android:layout_marginStart="8dp" + android:layout_marginTop="24dp" + android:gravity="center" + android:text="3" + android:textSize="18sp" + android:textStyle="bold" + app:layout_constraintEnd_toStartOf="@+id/number_picker_cols_positive" + app:layout_constraintStart_toEndOf="@+id/number_picker_cols_negative" + app:layout_constraintTop_toBottomOf="@+id/number_picker_row_count" /> + + <TextView + android:id="@+id/number_picker_cols_positive" + android:layout_width="30dp" + android:layout_height="30dp" + android:layout_marginEnd="8dp" + android:layout_marginRight="8dp" + android:layout_marginTop="24dp" + android:text="+" + android:gravity="center" + android:textSize="18sp" + android:textStyle="bold" + android:clickable="true" + android:background="@drawable/image_button_background" + app:layout_constraintEnd_toEndOf="@+id/numberpickerLayout" + app:layout_constraintTop_toBottomOf="@+id/number_picker_rows_positive" /> +</android.support.constraint.ConstraintLayout>
\ No newline at end of file diff --git a/android/source/res/layout/toolbar_bottom.xml b/android/source/res/layout/toolbar_bottom.xml index d944b2713f2a..d1476a57fa57 100644 --- a/android/source/res/layout/toolbar_bottom.xml +++ b/android/source/res/layout/toolbar_bottom.xml @@ -366,6 +366,26 @@ android:paddingBottom="12dp" android:paddingTop="12dp" app:srcCompat="@drawable/ic_folder_black_24dp" /> + + <ImageButton + android:id="@+id/button_insert_table" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="0.25" + android:background="@drawable/image_button_background" + android:paddingBottom="12dp" + android:paddingTop="12dp" + app:srcCompat="@drawable/ic_grid_on_black_24dp" /> + + <ImageButton + android:id="@+id/button_delete_table" + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="0.25" + android:background="@drawable/image_button_background" + android:paddingBottom="12dp" + android:paddingTop="12dp" + app:srcCompat="@drawable/ic_grid_off_black_24dp" /> </LinearLayout> </ScrollView> </LinearLayout> diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml index 2a4ca0ab4e21..cbbce88d158c 100644 --- a/android/source/res/values/strings.xml +++ b/android/source/res/values/strings.xml @@ -179,5 +179,21 @@ <string name="action_cut">Cut</string> <string name="action_back">Back</string> <string name="action_text_copied">Text copied to the clipboard</string> + <string name="insert_table">Insert table</string> + <string name="select_insert_options">Select insert options:</string> + <string name="select_delete_options">Select delete options:</string> + + <string-array name="insertrowscolumns"> + <item>Insert Rows Before</item> + <item>Insert Rows After</item> + <item>Insert Columns Before</item> + <item>Insert Columns After</item> + <item>Insert Table</item> + </string-array> + <string-array name="deleterowcolumns"> + <item>Delete Rows</item> + <item>Delete Columns</item> + <item>Delete Table</item> + </string-array> </resources> diff --git a/android/source/src/java/org/libreoffice/FormattingController.java b/android/source/src/java/org/libreoffice/FormattingController.java index 0ba72cf50875..0f49a57de997 100644 --- a/android/source/src/java/org/libreoffice/FormattingController.java +++ b/android/source/src/java/org/libreoffice/FormattingController.java @@ -14,8 +14,10 @@ import android.provider.MediaStore; import android.support.design.widget.Snackbar; import android.support.v4.content.FileProvider; import android.util.Log; +import android.view.LayoutInflater; import android.view.View; import android.widget.ImageButton; +import android.widget.TextView; import org.json.JSONException; import org.json.JSONObject; @@ -61,6 +63,9 @@ class FormattingController implements View.OnClickListener { mContext.findViewById(R.id.button_insert_rect).setOnClickListener(this); mContext.findViewById(R.id.button_insert_picture).setOnClickListener(this); + mContext.findViewById(R.id.button_insert_table).setOnClickListener(this); + mContext.findViewById(R.id.button_delete_table).setOnClickListener(this); + mContext.findViewById(R.id.button_font_shrink).setOnClickListener(this); mContext.findViewById(R.id.button_font_grow).setOnClickListener(this); @@ -132,6 +137,12 @@ class FormattingController implements View.OnClickListener { break; case R.id.button_insert_picture: insertPicture(); + case R.id.button_insert_table: + insertTable(); + break; + case R.id.button_delete_table: + deleteTable(); + break; } } @@ -208,6 +219,159 @@ class FormattingController implements View.OnClickListener { builder.show(); } + private void insertTable() { + final AlertDialog.Builder insertTableBuilder = new AlertDialog.Builder(mContext); + insertTableBuilder.setTitle(R.string.insert_table); + LayoutInflater layoutInflater = mContext.getLayoutInflater(); + View numberPicker = layoutInflater.inflate(R.layout.number_picker, null); + final int minValue = 1; + final int maxValue = 20; + TextView npRowPositive = numberPicker.findViewById(R.id.number_picker_rows_positive); + TextView npRowNegative = numberPicker.findViewById(R.id.number_picker_rows_negative); + TextView npColPositive = numberPicker.findViewById(R.id.number_picker_cols_positive); + TextView npColNegative = numberPicker.findViewById(R.id.number_picker_cols_negative); + final TextView npRowCount = numberPicker.findViewById(R.id.number_picker_row_count); + final TextView npColCount = numberPicker.findViewById(R.id.number_picker_col_count); + + View.OnClickListener positiveButtonClickListener = new View.OnClickListener() { + @Override + 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; + } + } + }; + + View.OnClickListener negativeButtonClickListener = new View.OnClickListener() { + @Override + 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; + } + } + }; + + npRowPositive.setOnClickListener(positiveButtonClickListener); + npColPositive.setOnClickListener(positiveButtonClickListener); + npRowNegative.setOnClickListener(negativeButtonClickListener); + npColNegative.setOnClickListener(negativeButtonClickListener); + + insertTableBuilder.setView(numberPicker); + insertTableBuilder.setNeutralButton("Cancel", null); + insertTableBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + + try { + JSONObject cols = new JSONObject(); + cols.put("type", "long"); + cols.put("value", Integer.valueOf(npColCount.getText().toString())); + JSONObject rows = new JSONObject(); + rows.put("type","long"); + rows.put("value",Integer.valueOf(npRowCount.getText().toString())); + JSONObject params = new JSONObject(); + params.put("Columns", cols); + params.put("Rows", rows); + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:InsertTable",params.toString())); + LibreOfficeMainActivity.setDocumentChanged(true); + } catch (JSONException e) { + e.printStackTrace(); + } + + } + }); + + AlertDialog.Builder insertBuilder = new AlertDialog.Builder(mContext); + insertBuilder.setTitle(R.string.select_insert_options); + insertBuilder.setNeutralButton("Cancel", null); + final int[] selectedItem = new int[1]; + insertBuilder.setSingleChoiceItems(mContext.getResources().getStringArray(R.array.insertrowscolumns), -1, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + selectedItem[0] = which; + } + }); + insertBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (selectedItem[0]){ + case 0: + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:InsertRowsBefore")); + LibreOfficeMainActivity.setDocumentChanged(true); + break; + case 1: + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:InsertRowsAfter")); + LibreOfficeMainActivity.setDocumentChanged(true); + break; + case 2: + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:InsertColumnsBefore")); + LibreOfficeMainActivity.setDocumentChanged(true); + break; + case 3: + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:InsertColumnsAfter")); + LibreOfficeMainActivity.setDocumentChanged(true); + break; + case 4: + insertTableBuilder.show(); + break; + + } + } + }); + insertBuilder.show(); + } + + private void deleteTable() { + AlertDialog.Builder deleteBuilder = new AlertDialog.Builder(mContext); + deleteBuilder.setTitle(R.string.select_delete_options); + deleteBuilder.setNeutralButton("Cancel",null); + final int[] selectedItem = new int[1]; + deleteBuilder.setSingleChoiceItems(mContext.getResources().getStringArray(R.array.deleterowcolumns), -1, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + selectedItem[0] = which; + } + }); + deleteBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + switch (selectedItem[0]){ + case 0: + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:DeleteRows")); + LibreOfficeMainActivity.setDocumentChanged(true); + break; + case 1: + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:DeleteColumns")); + LibreOfficeMainActivity.setDocumentChanged(true); + break; + case 2: + LOKitShell.sendEvent(new LOEvent(LOEvent.UNO_COMMAND, ".uno:DeleteTable")); + LibreOfficeMainActivity.setDocumentChanged(true); + break; + } + } + }); + deleteBuilder.show(); + } + private void sendImagePickingIntent() { Intent intent = new Intent(); intent.setType("image/*"); |