From f8fe3f082a8ee51a15dcf5c7b5c93fa6775421d4 Mon Sep 17 00:00:00 2001 From: meeh <meeh@mail.i2p> Date: Sun, 12 Aug 2012 04:02:24 +0000 Subject: [PATCH] Added support for building jni in osx. Also forgot to add new source files from last commit. --- res/layout/activity_addressbook_settings.xml | 52 +++++++++ routerjars/jni/build.sh | 18 +++- .../activity/AddressbookSettingsActivity.java | 102 ++++++++++++++++++ 3 files changed, 168 insertions(+), 4 deletions(-) create mode 100644 res/layout/activity_addressbook_settings.xml create mode 100644 src/net/i2p/android/router/activity/AddressbookSettingsActivity.java diff --git a/res/layout/activity_addressbook_settings.xml b/res/layout/activity_addressbook_settings.xml new file mode 100644 index 000000000..6dd4566c6 --- /dev/null +++ b/res/layout/activity_addressbook_settings.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="utf-8"?> +<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:fillViewport="true"> + + <LinearLayout + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" > + + <TextView + android:id="@+id/textView1" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:text="Addressbook Settings" + android:textAppearance="?android:attr/textAppearanceLarge" /> + + <FrameLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" > + + <TextView + android:id="@+id/textView2" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Subscriptions" + android:textAppearance="?android:attr/textAppearanceMedium" /> + + <EditText + android:id="@+id/subscriptions_content" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:ems="10" + android:inputType="textMultiLine" + android:maxLines="@integer/min_lines" + android:minLines="@integer/min_lines" > + + <requestFocus /> + </EditText> + + <Button + android:id="@+id/button_save_subscriptions" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="Save subscriptions.txt" /> + + </FrameLayout> + + </LinearLayout> + +</ScrollView> diff --git a/routerjars/jni/build.sh b/routerjars/jni/build.sh index 8319fc0ec..df29a74cb 100755 --- a/routerjars/jni/build.sh +++ b/routerjars/jni/build.sh @@ -14,7 +14,8 @@ # #THISDIR=$(realpath $(dirname $(which $0))) -THISDIR=$(dirname $(readlink -f $0)) +## Making it work on osx too. +THISDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $THISDIR LIBFILE=$PWD/libjbigi.so @@ -33,8 +34,13 @@ I2PBASE=${1:-../../../i2p.i2p} # the dot at the end ensures that it is a directory, and not a file. # #export NDK=$(realpath ../../android-ndk-r5b/) -export NDK=readlink -ne $(for last in ../../android-ndk-r*/.; do true; done ; echo $last) +## Simple fix for osx development +if [ "`uname -s`" == "Darwin" ]; then + export NDK=/Developer/android/ndk/ +else + export NDK=readlink -ne $(for last in ../../android-ndk-r*/.; do true; done ; echo $last) +fi # # API level, must match that in ../AndroidManifest.xml # @@ -51,7 +57,7 @@ STRIP="$NDK/toolchains/$AABI/prebuilt/$SYSTEM/bin/${BINPREFIX}strip" #echo "CC is $CC" -JBIGI=$(realpath $I2PBASE/core/c/jbigi) +JBIGI="$I2PBASE/core/c/jbigi" # # GMP Version # @@ -87,7 +93,11 @@ fi echo "Building GMP..." make || exit 1 -export JAVA_HOME=$(dirname $(dirname $(realpath $(which javac)))) +if [ "`uname -s`" == "Darwin" ]; then + export JAVA_HOME="/Library/Java/Home" +else + export JAVA_HOME=$(dirname $(dirname $(realpath $(which javac)))) +fi if [ ! -f "$JAVA_HOME/include/jni.h" ]; then echo "Cannot find jni.h! Looked in '$JAVA_HOME/include/jni.h'" echo "Please set JAVA_HOME to a java home that has the JNI" diff --git a/src/net/i2p/android/router/activity/AddressbookSettingsActivity.java b/src/net/i2p/android/router/activity/AddressbookSettingsActivity.java new file mode 100644 index 000000000..2cb4f264c --- /dev/null +++ b/src/net/i2p/android/router/activity/AddressbookSettingsActivity.java @@ -0,0 +1,102 @@ +package net.i2p.android.router.activity; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; + + +import net.i2p.android.router.R; +import android.os.Bundle; +import android.app.Activity; +import android.content.Context; +import android.util.Log; +import android.view.Menu; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +public class AddressbookSettingsActivity extends Activity { + + protected EditText text_content_subscriptions; + protected Button btn_save_subscriptions; + private String filename = "/addressbook/subscriptions.txt"; + private String i2pDir; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_addressbook_settings); + text_content_subscriptions = (EditText) findViewById(R.id.subscriptions_content); + btn_save_subscriptions = (Button) findViewById(R.id.button_save_subscriptions); + init_actions(); + i2pDir = getFilesDir().getAbsolutePath(); + load(); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.activity_addressbook_settings, menu); + return true; + } + + private void init_actions() { + btn_save_subscriptions.setOnClickListener(new View.OnClickListener() { + public void onClick(View view) { + Context context = getApplicationContext(); + CharSequence text = ""; + if (save()) { + text = "subscriptions.txt successfully saved!"; + } else { + text = "there was a problem saving subscriptions.txt! Try fix permissions or reinstall i2p."; + } + Toast.makeText(context, text, Toast.LENGTH_SHORT).show(); + } + }); + } + + private boolean load() { + String res = null; + FileInputStream in; + try { + in = new FileInputStream(new File(i2pDir+filename)); + if (in != null) { + InputStreamReader input = new InputStreamReader(in); + BufferedReader buffreader = new BufferedReader(input); + res=""; + String line = null; + while (( line = buffreader.readLine()) != null) { + res += line+"\n"; + } + in.close(); + text_content_subscriptions.setText(res); + return true; + } + } catch (Exception e) { + Log.e("I2P-AddressbookSettings", "Can't read subscriptions.txt"); + //TODO: Add error reporting support + e.printStackTrace(); + return false; + } + return false; + } + + private boolean save() { + // + String content = text_content_subscriptions.getText().toString(); + try { + FileOutputStream out = new FileOutputStream(new File(i2pDir+filename)); + byte[] contentInBytes = content.getBytes(); + out.write(contentInBytes); + out.flush(); + out.close(); + return true; + } catch (Exception e) { + e.printStackTrace(); + return false; + } + } +} -- GitLab