Android Toodle WIP (#1)
* Android app * rust portion of the app * correct symlinks for libtoodle.so, build script * Don't ignore create_item result * Move ctypes into their own module * More rusty result mapping; moving itemscbox into ctypes * remove comment * rename set to list
|
@ -1,9 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Greetings.iml" filepath="$PROJECT_DIR$/Greetings.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -1,22 +0,0 @@
|
|||
package com.mozilla.greetings;
|
||||
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class GreetingsActivity extends AppCompatActivity {
|
||||
|
||||
static {
|
||||
System.loadLibrary("greetings");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_greetings);
|
||||
|
||||
RustGreetings g = new RustGreetings();
|
||||
String r = g.sayHello("world");
|
||||
((TextView)findViewById(R.id.greetingField)).setText(r);
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package com.mozilla.greetings;
|
||||
|
||||
/**
|
||||
* Created by emilytoop on 01/09/2017.
|
||||
*/
|
||||
|
||||
public class RustGreetings {
|
||||
|
||||
private static native String greeting(final String pattern);
|
||||
|
||||
public String sayHello(String to) {
|
||||
return greeting(to);
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
/Users/emilytoop/Development/greetings/cargo/target/aarch64-linux-android/release/libgreetings.so
|
|
@ -1 +0,0 @@
|
|||
/Users/emilytoop/Development/greetings/cargo/target/armv7-linux-androideabi/release/libgreetings.so
|
|
@ -1 +0,0 @@
|
|||
/Users/emilytoop/Development/greetings/cargo/target/i686-linux-android/release/libgreetings.so
|
|
@ -1,18 +0,0 @@
|
|||
<?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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.mozilla.greetings.GreetingsActivity">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/greetingField"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
|
@ -1,3 +0,0 @@
|
|||
<resources>
|
||||
<string name="app_name">Greetings</string>
|
||||
</resources>
|
|
@ -1,11 +0,0 @@
|
|||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
|
@ -1,8 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="NullableNotNullManager">
|
||||
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
||||
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
||||
|
@ -27,17 +24,7 @@
|
|||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
||||
<OptionsSetting value="true" id="Add" />
|
||||
<OptionsSetting value="true" id="Remove" />
|
||||
<OptionsSetting value="true" id="Checkout" />
|
||||
<OptionsSetting value="true" id="Update" />
|
||||
<OptionsSetting value="true" id="Status" />
|
||||
<OptionsSetting value="true" id="Edit" />
|
||||
<ConfirmationsSetting value="0" id="Add" />
|
||||
<ConfirmationsSetting value="0" id="Remove" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Toodle.iml" filepath="$PROJECT_DIR$/Toodle.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/Toodle.iml" filepath="$PROJECT_DIR$/Toodle.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,10 +1,10 @@
|
|||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
|
||||
android {
|
||||
compileSdkVersion 26
|
||||
buildToolsVersion "26.0.1"
|
||||
defaultConfig {
|
||||
applicationId "com.mozilla.greetings"
|
||||
applicationId "com.mozilla.toodle"
|
||||
minSdkVersion 26
|
||||
targetSdkVersion 26
|
||||
versionCode 1
|
||||
|
@ -24,7 +24,13 @@ dependencies {
|
|||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
compile 'com.android.support:appcompat-v7:26.+'
|
||||
compile 'com.android.support:appcompat-v7:26.1.0'
|
||||
compile 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||
compile 'com.android.support:design:26.1.0'
|
||||
testCompile 'junit:junit:4.12'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
|
||||
compile 'net.java.dev.jna:jna:4.5.0'
|
||||
}
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.mozilla.greetings;
|
||||
package com.mozilla.toodle;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mozilla.greetings">
|
||||
package="com.mozilla.toodle">
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
@ -9,13 +9,22 @@
|
|||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".GreetingsActivity">
|
||||
<activity android:name=".ToodleActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".NewItemActivity"
|
||||
android:label="@string/title_activity_new_item"
|
||||
android:parentActivityName=".ToodleActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="com.mozilla.toodle.ToodleActivity" />
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -0,0 +1,67 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package com.mozilla.toodle;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.mozilla.toodle.rust.ListManager;
|
||||
import com.mozilla.toodle.rust.NativeItem;
|
||||
import com.mozilla.toodle.rust.Toodle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class Item {
|
||||
// private String uuid;
|
||||
private String name;
|
||||
private Long dueDate;
|
||||
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
Item name(final String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Long dueDate() {
|
||||
return dueDate;
|
||||
}
|
||||
|
||||
Item dueDate(final int year, final int month, final int date) {
|
||||
// TODO pretty sure this is wrong, somehow.
|
||||
final Date dd = new Date(year, month, date);
|
||||
dueDate = dd.getTime();
|
||||
return this;
|
||||
}
|
||||
|
||||
private static Item fromNativeItem(NativeItem nativeItem) {
|
||||
final Item item = new Item();
|
||||
item.name = nativeItem.itemName;
|
||||
// item.uuid = nativeItem.uuid;
|
||||
return item;
|
||||
}
|
||||
|
||||
static ArrayList<Item> fromNativeItems(List<NativeItem> nativeItems) {
|
||||
final ArrayList<Item> items = new ArrayList<>(nativeItems.size());
|
||||
|
||||
for (NativeItem nativeItem : nativeItems) {
|
||||
items.add(fromNativeItem(nativeItem));
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
void create(Context context) {
|
||||
try (final Toodle toodle = new Toodle(context)) {
|
||||
try (final ListManager listManager = toodle.getListManager()) {
|
||||
listManager.createItem(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package com.mozilla.toodle;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mozilla.toodle.rust.NativeItemSet;
|
||||
import com.mozilla.toodle.rust.NativeItemsCallback;
|
||||
import com.mozilla.toodle.rust.NativeItemsChangedCallback;
|
||||
import com.mozilla.toodle.rust.ListManager;
|
||||
import com.mozilla.toodle.rust.Toodle;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ViewHolder> {
|
||||
private List<Item> dataset = new ArrayList<>(0);
|
||||
private final Context context;
|
||||
|
||||
static class NativeItemsCallbackInner implements NativeItemsChangedCallback {
|
||||
private final WeakReference<ListAdapter> listAdapterWeakReference;
|
||||
|
||||
NativeItemsCallbackInner(WeakReference<ListAdapter> listAdapterWeakReference) {
|
||||
this.listAdapterWeakReference = listAdapterWeakReference;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void items() {
|
||||
final ListAdapter listAdapter = listAdapterWeakReference.get();
|
||||
if (listAdapter == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Log.i("RustyToodleJava", "Items changed!");
|
||||
try (final Toodle toodle = new Toodle(listAdapter.context)) {
|
||||
try (final ListManager listManager = toodle.getListManager()) {
|
||||
listManager.getAllItems(new NativeItemsCallback() {
|
||||
@Override
|
||||
public void items(@Nullable NativeItemSet.ByReference itemSet) {
|
||||
if (itemSet == null) {
|
||||
Log.i("RustyToodleJava", "Got no items!");
|
||||
listAdapter.dataset = new ArrayList<>(0);
|
||||
return;
|
||||
}
|
||||
Log.i("RustyToodleJava", "Got " + itemSet.size() + " items!");
|
||||
listAdapter.dataset = Item.fromNativeItems(itemSet.getItems());
|
||||
listAdapter.notifyDataSetChanged();
|
||||
itemSet.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We must keep reference to the callback around, otherwise it'll get GC'd and the native code
|
||||
// will call an empty stub instead of our callback.
|
||||
private final NativeItemsChangedCallback nativeItemsChangedCallback = new NativeItemsCallbackInner(
|
||||
new WeakReference<>(this)
|
||||
);
|
||||
|
||||
ListAdapter(Context context) {
|
||||
this.context = context;
|
||||
|
||||
try (final Toodle toodle = new Toodle(context)) {
|
||||
try (final ListManager listManager = toodle.getListManager()) {
|
||||
listManager.registerChangedItemsCallback(nativeItemsChangedCallback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
private final LinearLayout itemView;
|
||||
|
||||
ViewHolder(LinearLayout v) {
|
||||
super(v);
|
||||
itemView = v;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
final LinearLayout v = (LinearLayout) LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.item, parent, false);
|
||||
|
||||
return new ViewHolder(v);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
((TextView) holder.itemView.findViewById(R.id.itemTitle)).setText(dataset.get(position).name());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return dataset.size();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package com.mozilla.toodle;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class NewItemActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_new_item);
|
||||
|
||||
final TextView itemName = findViewById(R.id.itemName);
|
||||
final DatePicker itemDueDate = findViewById(R.id.itemDueDate);
|
||||
final Button addBtn = findViewById(R.id.itemAdd);
|
||||
|
||||
addBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final String name = itemName.getText().toString();
|
||||
final int yearDue = itemDueDate.getYear();
|
||||
final int monthDue = itemDueDate.getMonth();
|
||||
final int dayDue = itemDueDate.getDayOfMonth();
|
||||
|
||||
final Item item = new Item();
|
||||
|
||||
item
|
||||
.name(name)
|
||||
.dueDate(yearDue, monthDue, dayDue)
|
||||
.create(getApplicationContext());
|
||||
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package com.mozilla.toodle;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
public class ToodleActivity extends Activity {
|
||||
private RecyclerView listRecyclerView;
|
||||
private RecyclerView.Adapter listAdapter;
|
||||
private RecyclerView.LayoutManager layoutManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_toodle);
|
||||
|
||||
listRecyclerView = findViewById(R.id.listItems);
|
||||
|
||||
layoutManager = new LinearLayoutManager(this);
|
||||
listRecyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
listAdapter = new ListAdapter(getApplicationContext());
|
||||
listRecyclerView.setAdapter(listAdapter);
|
||||
|
||||
final FloatingActionButton newItemBtn = findViewById(R.id.newItem);
|
||||
newItemBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
startActivity(new Intent(ToodleActivity.this, NewItemActivity.class));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package com.mozilla.toodle.rust;
|
||||
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.NativeLibrary;
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
public interface JNA extends Library {
|
||||
String JNA_LIBRARY_NAME = "toodle";
|
||||
NativeLibrary JNA_NATIVE_LIB = NativeLibrary.getInstance(JNA_LIBRARY_NAME);
|
||||
|
||||
JNA INSTANCE = (JNA) Native.loadLibrary(JNA_LIBRARY_NAME, JNA.class);
|
||||
|
||||
Pointer new_toodle(String dbPath);
|
||||
void toodle_destroy(Pointer toodle);
|
||||
|
||||
Pointer toodle_list(Pointer toodle);
|
||||
void toodle_list_destroy(Pointer listManager);
|
||||
|
||||
void list_manager_create_item(Pointer listManager, String name, long dueDate);
|
||||
void list_manager_on_items_changed(NativeItemsChangedCallback callback);
|
||||
void list_manager_all_items(Pointer listManager, NativeItemsCallback callback);
|
||||
void item_c_destroy(Pointer item);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package com.mozilla.toodle.rust;
|
||||
|
||||
import com.mozilla.toodle.Item;
|
||||
|
||||
public class ListManager extends RustObject {
|
||||
/* package-private */ ListManager(Toodle toodle) {
|
||||
rawPointer = JNA.INSTANCE.toodle_list(toodle.rawPointer);
|
||||
}
|
||||
|
||||
public void createItem(Item item) {
|
||||
JNA.INSTANCE.list_manager_create_item(
|
||||
rawPointer,
|
||||
item.name(),
|
||||
item.dueDate()
|
||||
);
|
||||
}
|
||||
|
||||
public void registerChangedItemsCallback(NativeItemsChangedCallback callback) {
|
||||
JNA.INSTANCE.list_manager_on_items_changed(callback);
|
||||
}
|
||||
|
||||
public void getAllItems(NativeItemsCallback callback) {
|
||||
JNA.INSTANCE.list_manager_all_items(rawPointer, callback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
JNA.INSTANCE.toodle_list_destroy(rawPointer);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.mozilla.toodle.rust;
|
||||
|
||||
import com.sun.jna.Structure;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class NativeItem extends Structure implements Closeable {
|
||||
public static class ByReference extends NativeItem implements Structure.ByReference {
|
||||
}
|
||||
|
||||
public static class ByValue extends NativeItem implements Structure.ByValue {
|
||||
}
|
||||
|
||||
// public String uuid;
|
||||
public String itemName;
|
||||
// public Long dueDate;
|
||||
// public Long completionDate;
|
||||
|
||||
@Override
|
||||
protected List<String> getFieldOrder() {
|
||||
return Arrays.asList("uuid", "itemName");//, "dueDate", "completionDate");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
JNA.INSTANCE.item_c_destroy(this.getPointer());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.mozilla.toodle.rust;
|
||||
|
||||
import com.sun.jna.Structure;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class NativeItemSet extends Structure implements Closeable {
|
||||
public static class ByReference extends NativeItemSet implements Structure.ByReference {
|
||||
}
|
||||
|
||||
public static class ByValue extends NativeItemSet implements Structure.ByValue {
|
||||
}
|
||||
|
||||
public NativeItem.ByReference items;
|
||||
public int numberOfItems;
|
||||
|
||||
public List<NativeItem> getItems() {
|
||||
final NativeItem[] array = (NativeItem[]) items.toArray(numberOfItems);
|
||||
return Arrays.asList(array);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getFieldOrder() {
|
||||
return Arrays.asList("items", "numberOfItems");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
final NativeItem[] nativeItems = (NativeItem[]) items.toArray(numberOfItems);
|
||||
for (NativeItem nativeItem : nativeItems) {
|
||||
nativeItem.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.mozilla.toodle.rust;
|
||||
|
||||
import com.sun.jna.Callback;
|
||||
|
||||
public interface NativeItemUuidsCallback extends Callback {
|
||||
void uuids(UuidSet.ByReference uuids);
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.mozilla.toodle.rust;
|
||||
|
||||
import com.sun.jna.Callback;
|
||||
|
||||
public interface NativeItemsCallback extends Callback {
|
||||
void items(NativeItemSet.ByReference items);
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package com.mozilla.toodle.rust;
|
||||
|
||||
import com.sun.jna.Callback;
|
||||
|
||||
public interface NativeItemsChangedCallback extends Callback {
|
||||
void items();
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package com.mozilla.toodle.rust;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
/* package-private */ abstract class RustObject implements Closeable {
|
||||
Pointer rawPointer;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package com.mozilla.toodle.rust;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class Toodle extends RustObject {
|
||||
static {
|
||||
System.loadLibrary("toodle");
|
||||
}
|
||||
|
||||
private static final String DB_NAME = "toodle.db";
|
||||
|
||||
public Toodle(Context context) {
|
||||
this.rawPointer = JNA.INSTANCE.new_toodle(
|
||||
context.getDatabasePath(DB_NAME).getAbsolutePath()
|
||||
);
|
||||
}
|
||||
|
||||
public ListManager getListManager() {
|
||||
return new ListManager(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
JNA.INSTANCE.toodle_destroy(rawPointer);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.mozilla.toodle.rust;
|
||||
|
||||
import com.sun.jna.Structure;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Uuid extends Structure implements Closeable {
|
||||
public static class ByReference extends Uuid implements Structure.ByReference {
|
||||
}
|
||||
|
||||
public static class ByValue extends Uuid implements Structure.ByValue {
|
||||
}
|
||||
|
||||
public String uuid;
|
||||
|
||||
@Override
|
||||
protected List<String> getFieldOrder() {
|
||||
return Arrays.asList("uuid");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// TODO
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.mozilla.toodle.rust;
|
||||
|
||||
import com.sun.jna.Structure;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class UuidSet extends Structure implements Closeable {
|
||||
public static class ByReference extends UuidSet implements Structure.ByReference {
|
||||
}
|
||||
|
||||
public static class ByValue extends UuidSet implements Structure.ByValue {
|
||||
}
|
||||
|
||||
public Uuid.ByReference uuids;
|
||||
|
||||
public int numberOfUuids;
|
||||
|
||||
public List<Uuid> getUuids() {
|
||||
Uuid[] array = (Uuid[]) uuids.toArray(numberOfUuids);
|
||||
return Arrays.asList(array);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getFieldOrder() {
|
||||
return Arrays.asList("uuids", "numberOfUuids");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// TODO
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../rust/target/aarch64-linux-android/debug/libtoodle.so
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../rust/target/armv7-linux-androideabi/debug/libtoodle.so
|
|
@ -0,0 +1 @@
|
|||
../../../../../../../rust/target/i686-linux-android/debug/libtoodle.so
|
После Ширина: | Высота: | Размер: 451 B |
После Ширина: | Высота: | Размер: 446 B |
После Ширина: | Высота: | Размер: 491 B |
После Ширина: | Высота: | Размер: 460 B |
После Ширина: | Высота: | Размер: 491 B |
После Ширина: | Высота: | Размер: 489 B |
После Ширина: | Высота: | Размер: 525 B |
После Ширина: | Высота: | Размер: 473 B |
После Ширина: | Высота: | Размер: 435 B |
После Ширина: | Высота: | Размер: 453 B |
После Ширина: | Высота: | Размер: 500 B |
После Ширина: | Высота: | Размер: 470 B |
После Ширина: | Высота: | Размер: 386 B |
После Ширина: | Высота: | Размер: 369 B |
После Ширина: | Высота: | Размер: 446 B |
После Ширина: | Высота: | Размер: 401 B |
После Ширина: | Высота: | Размер: 407 B |
После Ширина: | Высота: | Размер: 379 B |
После Ширина: | Высота: | Размер: 489 B |
После Ширина: | Высота: | Размер: 414 B |
После Ширина: | Высота: | Размер: 393 B |
После Ширина: | Высота: | Размер: 373 B |
После Ширина: | Высота: | Размер: 453 B |
После Ширина: | Высота: | Размер: 411 B |
После Ширина: | Высота: | Размер: 446 B |
После Ширина: | Высота: | Размер: 401 B |
После Ширина: | Высота: | Размер: 460 B |
После Ширина: | Высота: | Размер: 508 B |
После Ширина: | Высота: | Размер: 489 B |
После Ширина: | Высота: | Размер: 414 B |
После Ширина: | Высота: | Размер: 473 B |
После Ширина: | Высота: | Размер: 518 B |
После Ширина: | Высота: | Размер: 453 B |
После Ширина: | Высота: | Размер: 411 B |
После Ширина: | Высота: | Размер: 470 B |
После Ширина: | Высота: | Размер: 515 B |
После Ширина: | Высота: | Размер: 491 B |
После Ширина: | Высота: | Размер: 460 B |
После Ширина: | Высота: | Размер: 604 B |
После Ширина: | Высота: | Размер: 615 B |
Двоичные данные
android/Toodle/app/src/main/res/drawable-xxhdpi/ic_plus_grey600_18dp.png
Normal file
После Ширина: | Высота: | Размер: 525 B |
Двоичные данные
android/Toodle/app/src/main/res/drawable-xxhdpi/ic_plus_grey600_24dp.png
Normal file
После Ширина: | Высота: | Размер: 473 B |
Двоичные данные
android/Toodle/app/src/main/res/drawable-xxhdpi/ic_plus_grey600_36dp.png
Normal file
После Ширина: | Высота: | Размер: 663 B |
Двоичные данные
android/Toodle/app/src/main/res/drawable-xxhdpi/ic_plus_grey600_48dp.png
Normal file
После Ширина: | Высота: | Размер: 622 B |
После Ширина: | Высота: | Размер: 500 B |
После Ширина: | Высота: | Размер: 470 B |
После Ширина: | Высота: | Размер: 622 B |
После Ширина: | Высота: | Размер: 619 B |
После Ширина: | Высота: | Размер: 460 B |
После Ширина: | Высота: | Размер: 508 B |
После Ширина: | Высота: | Размер: 615 B |
После Ширина: | Высота: | Размер: 735 B |
Двоичные данные
android/Toodle/app/src/main/res/drawable-xxxhdpi/ic_plus_grey600_18dp.png
Normal file
После Ширина: | Высота: | Размер: 473 B |
Двоичные данные
android/Toodle/app/src/main/res/drawable-xxxhdpi/ic_plus_grey600_24dp.png
Normal file
После Ширина: | Высота: | Размер: 518 B |
Двоичные данные
android/Toodle/app/src/main/res/drawable-xxxhdpi/ic_plus_grey600_36dp.png
Normal file
После Ширина: | Высота: | Размер: 622 B |
Двоичные данные
android/Toodle/app/src/main/res/drawable-xxxhdpi/ic_plus_grey600_48dp.png
Normal file
После Ширина: | Высота: | Размер: 750 B |
После Ширина: | Высота: | Размер: 470 B |