diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-08-10 22:53:21 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-08-10 23:00:45 +0200 |
commit | b69f5a1857d2dcad4b234ad84cde98b9fd436f90 (patch) | |
tree | 465a7d34184f4cd56bfde8bb09945e6055ece21a /android | |
parent | 5af2c260488f04696f01adcf26c24036820f96ff (diff) |
LOAndroid3: Add a side drawer to show available parts (by name)
Use DrawerLayer to show a side drawer with parts of the loaded
document. The dawer consists of an image (could be changed by a
thumbnail in the future) and the part name.
Change-Id: I27fb6112d9f11e19f3295ace97103b89816591aa
Diffstat (limited to 'android')
10 files changed, 204 insertions, 31 deletions
diff --git a/android/experimental/LOAndroid3/res/layout/activity_main.xml b/android/experimental/LOAndroid3/res/layout/activity_main.xml index 7b53d58a2b5c..1d09af984da2 100644 --- a/android/experimental/LOAndroid3/res/layout/activity_main.xml +++ b/android/experimental/LOAndroid3/res/layout/activity_main.xml @@ -1,15 +1,35 @@ <?xml version="1.0" encoding="utf-8"?> -<LinearLayout +<android.support.v4.widget.DrawerLayout + android:id="@+id/drawer_layout" xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/main_layout" - android:background="#fff" + xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" - android:layout_height="fill_parent"> + android:layout_height="fill_parent" + android:background="#fff" + tools:context=".MainActivity"> <RelativeLayout - android:id="@+id/gecko_layout" - android:layout_width="fill_parent" - android:layout_height="fill_parent" - android:layout_weight="1"/> + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <RelativeLayout + android:id="@+id/gecko_layout" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:layout_weight="1"/> + + <View + android:layout_width="match_parent" + android:layout_height="match_parent"/> + + </RelativeLayout> + + <ListView + android:id="@+id/left_drawer" + android:layout_width="240dp" + android:layout_height="match_parent" + android:layout_gravity="start" + android:background="#9FFF" + android:choiceMode="singleChoice"/> -</LinearLayout>
\ No newline at end of file +</android.support.v4.widget.DrawerLayout> diff --git a/android/experimental/LOAndroid3/res/layout/document_part_list_layout.xml b/android/experimental/LOAndroid3/res/layout/document_part_list_layout.xml new file mode 100644 index 000000000000..51ce0e0baea0 --- /dev/null +++ b/android/experimental/LOAndroid3/res/layout/document_part_list_layout.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:gravity="center_horizontal"> + + <ImageView + android:id="@+id/image" + android:layout_width="128dp" + android:layout_height="128dp"/> + + <TextView + android:id="@+id/text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Large Text" + android:textAppearance="?android:attr/textAppearanceLarge"/> +</LinearLayout>
\ No newline at end of file diff --git a/android/experimental/LOAndroid3/res/menu/main.xml b/android/experimental/LOAndroid3/res/menu/main.xml index e9709c90d729..d51872bed9d1 100644 --- a/android/experimental/LOAndroid3/res/menu/main.xml +++ b/android/experimental/LOAndroid3/res/menu/main.xml @@ -1,8 +1,13 @@ <menu 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" - tools:context="org.libreoffice.MainActivity" > + tools:context="org.libreoffice.MainActivity"> + <item android:id="@+id/action_settings" android:title="@string/action_settings" android:orderInCategory="100" /> + + <item android:id="@+id/action_list" + android:title="@string/action_list" + android:orderInCategory="100" /> </menu> diff --git a/android/experimental/LOAndroid3/res/values/strings.xml b/android/experimental/LOAndroid3/res/values/strings.xml index 93431ed24788..d776082191a7 100644 --- a/android/experimental/LOAndroid3/res/values/strings.xml +++ b/android/experimental/LOAndroid3/res/values/strings.xml @@ -3,5 +3,6 @@ <string name="app_name">LibreOffice</string> <string name="action_settings">Settings</string> + <string name="action_list">Parts</string> </resources> diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/DocumentPartView.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/DocumentPartView.java new file mode 100644 index 000000000000..436e37e8c460 --- /dev/null +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/DocumentPartView.java @@ -0,0 +1,14 @@ +package org.libreoffice; + + +public class DocumentPartView { + private String partName; + + public DocumentPartView(String partName) { + this.partName = partName; + } + + public String getPartName() { + return partName; + } +} diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/DocumentPartViewListAdpater.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/DocumentPartViewListAdpater.java new file mode 100644 index 000000000000..5ec49e13e4b4 --- /dev/null +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/DocumentPartViewListAdpater.java @@ -0,0 +1,41 @@ +package org.libreoffice; + +import android.app.Activity; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.TextView; + +import java.util.List; + +public class DocumentPartViewListAdpater extends ArrayAdapter<DocumentPartView> { + private static final String LOGTAG = DocumentPartViewListAdpater.class.getSimpleName(); + + private final Activity activity; + + public DocumentPartViewListAdpater(Activity activity, int resource, List<DocumentPartView> objects) { + super(activity, resource, objects); + this.activity = activity; + } + + @Override + public View getView(int position, View view, ViewGroup parent) { + if (view == null) { + LayoutInflater layoutInflater = activity.getLayoutInflater(); + view = layoutInflater.inflate(R.layout.document_part_list_layout, null); + } + + DocumentPartView documentPartView = getItem(position); + TextView textView = (TextView) view.findViewById(R.id.text); + textView.setText(documentPartView.getPartName()); + Log.i(LOGTAG, "getView - " + documentPartView.getPartName()); + + ImageView imageView = (ImageView) view.findViewById(R.id.image); + imageView.setImageResource(R.drawable.writer); + + return view; + } +} diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java index 4ceeddc99275..0d44d66f0a2c 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitShell.java @@ -1,6 +1,7 @@ package org.libreoffice; +import android.os.Handler; import android.util.DisplayMetrics; public class LOKitShell { @@ -32,4 +33,9 @@ public class LOKitShell { public static void scheduleResumeComposition() { } + + // Get a Handler for the main java thread + public static Handler getMainHandler() { + return LibreOfficeMainActivity.mAppContext.mMainHandler; + } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java index c5e2621a0cb5..4758b70838f0 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LOKitTileProvider.java @@ -55,6 +55,22 @@ public class LOKitTileProvider implements TileProvider { if (parts >= 1) { mDocument.setPart(0); } + for (int i = 0; i < parts; i++) { + String partName = mDocument.getPartName(i); + if (partName.isEmpty()) { + partName = "Part " + (i + 1); + } + Log.i(LOGTAG, "Document part " + i + " name:'" + partName + "'"); + final DocumentPartView partView = new DocumentPartView(partName); + LibreOfficeMainActivity.mAppContext.getDocumentPartView().add(partView); + } + + LibreOfficeMainActivity.mAppContext.mMainHandler.post(new Runnable() { + @Override + public void run() { + LibreOfficeMainActivity.mAppContext.getDocumentPartViewListAdpater().notifyDataSetChanged(); + } + }); } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java index 888db323fe43..c50fba4b6a9d 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/LibreOfficeMainActivity.java @@ -2,35 +2,53 @@ package org.libreoffice; import android.app.Activity; import android.os.Bundle; -import android.os.SystemClock; +import android.os.Handler; +import android.support.v4.widget.DrawerLayout; import android.util.DisplayMetrics; import android.util.Log; import android.view.Menu; import android.view.MenuItem; -import android.widget.LinearLayout; +import android.widget.ListView; import android.widget.RelativeLayout; import org.mozilla.gecko.gfx.GeckoLayerClient; import org.mozilla.gecko.gfx.LayerController; +import java.util.ArrayList; +import java.util.List; + public class LibreOfficeMainActivity extends Activity { private static final String LOGTAG = "LibreOfficeMainActivity"; private static final String DEFAULT_DOC_PATH = "/assets/test1.odt"; - private LinearLayout mMainLayout; - private RelativeLayout mGeckoLayout; + public static LibreOfficeMainActivity mAppContext; + private static LayerController mLayerController; private static GeckoLayerClient mLayerClient; private static LOKitThread sLOKitThread; - public static LibreOfficeMainActivity mAppContext; + public Handler mMainHandler; + + private DrawerLayout mDrawerLayout; + private RelativeLayout mGeckoLayout; + private ListView mDrawerList; + private List<DocumentPartView> mDocumentPartView = new ArrayList<DocumentPartView>(); + private DocumentPartViewListAdpater mDocumentPartViewListAdpater; + + public static GeckoLayerClient getLayerClient() { + return mLayerClient; + } + + public static LayerController getLayerController() { + return mLayerController; + } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); - return true; + return super.onCreateOptionsMenu(menu); } @Override @@ -45,36 +63,47 @@ public class LibreOfficeMainActivity extends Activity { return super.onOptionsItemSelected(item); } + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + // If the nav drawer is open, hide action items related to the content view + boolean drawerOpen = mDrawerLayout.isDrawerOpen(mDrawerList); + menu.findItem(R.id.action_list).setVisible(!drawerOpen); + return super.onPrepareOptionsMenu(menu); + } + public DisplayMetrics getDisplayMetrics() { DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); return metrics; } - /** - * Called when the activity is first created. - */ @Override public void onCreate(Bundle savedInstanceState) { mAppContext = this; + mMainHandler = new Handler(); + super.onCreate(savedInstanceState); - Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onCreate"); + String inputFile; - String inputFile = new String(); if (getIntent().getData() != null) { inputFile = getIntent().getData().getEncodedPath(); - } - else { + } else { inputFile = DEFAULT_DOC_PATH; } setContentView(R.layout.activity_main); - // setup gecko layout + getActionBar().setDisplayHomeAsUpEnabled(false); + getActionBar().setHomeButtonEnabled(false); + mGeckoLayout = (RelativeLayout) findViewById(R.id.gecko_layout); - mMainLayout = (LinearLayout) findViewById(R.id.main_layout); + mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); + mDrawerList = (ListView) findViewById(R.id.left_drawer); + + mDocumentPartViewListAdpater = new DocumentPartViewListAdpater(this, R.layout.document_part_list_layout, mDocumentPartView); + mDrawerList.setAdapter(mDocumentPartViewListAdpater); if (mLayerController == null) { mLayerController = new LayerController(this); @@ -90,19 +119,28 @@ public class LibreOfficeMainActivity extends Activity { sLOKitThread = new LOKitThread(inputFile); sLOKitThread.start(); - Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - UI almost up"); + Log.w(LOGTAG, "UI almost up"); + } + + @Override + protected void onResume() { + super.onResume(); + } + + @Override + protected void onPause() { + super.onPause(); } public LOKitThread getLOKitThread() { return sLOKitThread; } - public static GeckoLayerClient getLayerClient() { - return mLayerClient; + public List<DocumentPartView> getDocumentPartView() { + return mDocumentPartView; } - - public static LayerController getLayerController() { - return mLayerController; + public DocumentPartViewListAdpater getDocumentPartViewListAdpater() { + return mDocumentPartViewListAdpater; } } diff --git a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java index 1515d9ccd334..e7ced82c4fd6 100644 --- a/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java +++ b/android/experimental/LOAndroid3/src/java/org/libreoffice/MockTileProvider.java @@ -15,6 +15,18 @@ public class MockTileProvider implements TileProvider { public MockTileProvider(LayerController layerController, String inputFile) { this.layerController = layerController; this.inputFile = inputFile; + + for (int i = 0; i < 5; i++) { + String partName = "Part " + i; + DocumentPartView partView = new DocumentPartView(partName); + LibreOfficeMainActivity.mAppContext.getDocumentPartViewListAdpater().add(partView); + } + LibreOfficeMainActivity.mAppContext.mMainHandler.post(new Runnable() { + @Override + public void run() { + LibreOfficeMainActivity.mAppContext.getDocumentPartViewListAdpater().notifyDataSetChanged(); + } + }); } @Override |