Kaydet (Commit) b69f5a18 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl

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
üst 5af2c260
<?xml version="1.0" encoding="utf-8"?> <?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" xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout" xmlns:tools="http://schemas.android.com/tools"
android:background="#fff"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent"> android:layout_height="fill_parent"
android:background="#fff"
tools:context=".MainActivity">
<RelativeLayout <RelativeLayout
android:id="@+id/gecko_layout" android:layout_width="match_parent"
android:layout_width="fill_parent" android:layout_height="match_parent">
android:layout_height="fill_parent"
android:layout_weight="1"/> <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> </android.support.v4.widget.DrawerLayout>
\ No newline at end of file
<?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
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
tools:context="org.libreoffice.MainActivity" > tools:context="org.libreoffice.MainActivity">
<item android:id="@+id/action_settings" <item android:id="@+id/action_settings"
android:title="@string/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" /> android:orderInCategory="100" />
<item android:id="@+id/action_list"
android:title="@string/action_list"
android:orderInCategory="100" />
</menu> </menu>
...@@ -3,5 +3,6 @@ ...@@ -3,5 +3,6 @@
<string name="app_name">LibreOffice</string> <string name="app_name">LibreOffice</string>
<string name="action_settings">Settings</string> <string name="action_settings">Settings</string>
<string name="action_list">Parts</string>
</resources> </resources>
package org.libreoffice;
public class DocumentPartView {
private String partName;
public DocumentPartView(String partName) {
this.partName = partName;
}
public String getPartName() {
return partName;
}
}
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;
}
}
package org.libreoffice; package org.libreoffice;
import android.os.Handler;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
public class LOKitShell { public class LOKitShell {
...@@ -32,4 +33,9 @@ public class LOKitShell { ...@@ -32,4 +33,9 @@ public class LOKitShell {
public static void scheduleResumeComposition() { public static void scheduleResumeComposition() {
} }
// Get a Handler for the main java thread
public static Handler getMainHandler() {
return LibreOfficeMainActivity.mAppContext.mMainHandler;
}
} }
...@@ -55,6 +55,22 @@ public class LOKitTileProvider implements TileProvider { ...@@ -55,6 +55,22 @@ public class LOKitTileProvider implements TileProvider {
if (parts >= 1) { if (parts >= 1) {
mDocument.setPart(0); 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();
}
});
} }
} }
......
...@@ -2,35 +2,53 @@ package org.libreoffice; ...@@ -2,35 +2,53 @@ package org.libreoffice;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; 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.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.LinearLayout; import android.widget.ListView;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import org.mozilla.gecko.gfx.GeckoLayerClient; import org.mozilla.gecko.gfx.GeckoLayerClient;
import org.mozilla.gecko.gfx.LayerController; import org.mozilla.gecko.gfx.LayerController;
import java.util.ArrayList;
import java.util.List;
public class LibreOfficeMainActivity extends Activity { public class LibreOfficeMainActivity extends Activity {
private static final String LOGTAG = "LibreOfficeMainActivity"; private static final String LOGTAG = "LibreOfficeMainActivity";
private static final String DEFAULT_DOC_PATH = "/assets/test1.odt"; private static final String DEFAULT_DOC_PATH = "/assets/test1.odt";
private LinearLayout mMainLayout; public static LibreOfficeMainActivity mAppContext;
private RelativeLayout mGeckoLayout;
private static LayerController mLayerController; private static LayerController mLayerController;
private static GeckoLayerClient mLayerClient; private static GeckoLayerClient mLayerClient;
private static LOKitThread sLOKitThread; 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 @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present. // Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu); getMenuInflater().inflate(R.menu.main, menu);
return true; return super.onCreateOptionsMenu(menu);
} }
@Override @Override
...@@ -45,36 +63,47 @@ public class LibreOfficeMainActivity extends Activity { ...@@ -45,36 +63,47 @@ public class LibreOfficeMainActivity extends Activity {
return super.onOptionsItemSelected(item); 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() { public DisplayMetrics getDisplayMetrics() {
DisplayMetrics metrics = new DisplayMetrics(); DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics); getWindowManager().getDefaultDisplay().getMetrics(metrics);
return metrics; return metrics;
} }
/**
* Called when the activity is first created.
*/
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
mAppContext = this; mAppContext = this;
mMainHandler = new Handler();
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onCreate"); String inputFile;
String inputFile = new String();
if (getIntent().getData() != null) { if (getIntent().getData() != null) {
inputFile = getIntent().getData().getEncodedPath(); inputFile = getIntent().getData().getEncodedPath();
} } else {
else {
inputFile = DEFAULT_DOC_PATH; inputFile = DEFAULT_DOC_PATH;
} }
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
// setup gecko layout getActionBar().setDisplayHomeAsUpEnabled(false);
getActionBar().setHomeButtonEnabled(false);
mGeckoLayout = (RelativeLayout) findViewById(R.id.gecko_layout); 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) { if (mLayerController == null) {
mLayerController = new LayerController(this); mLayerController = new LayerController(this);
...@@ -90,19 +119,28 @@ public class LibreOfficeMainActivity extends Activity { ...@@ -90,19 +119,28 @@ public class LibreOfficeMainActivity extends Activity {
sLOKitThread = new LOKitThread(inputFile); sLOKitThread = new LOKitThread(inputFile);
sLOKitThread.start(); 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() { public LOKitThread getLOKitThread() {
return sLOKitThread; return sLOKitThread;
} }
public static GeckoLayerClient getLayerClient() { public List<DocumentPartView> getDocumentPartView() {
return mLayerClient; return mDocumentPartView;
} }
public DocumentPartViewListAdpater getDocumentPartViewListAdpater() {
public static LayerController getLayerController() { return mDocumentPartViewListAdpater;
return mLayerController;
} }
} }
......
...@@ -15,6 +15,18 @@ public class MockTileProvider implements TileProvider { ...@@ -15,6 +15,18 @@ public class MockTileProvider implements TileProvider {
public MockTileProvider(LayerController layerController, String inputFile) { public MockTileProvider(LayerController layerController, String inputFile) {
this.layerController = layerController; this.layerController = layerController;
this.inputFile = inputFile; 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 @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment