Cleaning:

- cleaned test app;
- moved android specific code to its own library (ethereum-core-android);
- moved ethereum-core from android library build back to java build;
This commit is contained in:
Adrian Tiberius 2015-05-30 00:42:03 +02:00
parent c123b52182
commit e46c7b59db
52 changed files with 1574 additions and 863 deletions

View File

@ -1,22 +1,11 @@
apply plugin: 'com.android.application'
apply plugin: 'com.neenbedankt.android-apt'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
mavenCentral()
flatDir {
dirs "../libraries", "../ethereum-core/libs"
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
@ -43,6 +32,7 @@ android {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
dexOptions {
javaMaxHeapSize "4g"
@ -61,13 +51,9 @@ android {
}
dependencies {
apt 'com.google.dagger:dagger-compiler:2.0'
compile 'com.google.dagger:dagger:2.0'
compile project(':ethereumj-core-android')
compile 'com.android.support:multidex:1.0.0'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile project(':ethereumj-core')
compile fileTree(include: ['*.jar'], dir: '../libraries')
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'com.android.support:support-v4:22.1.1'
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:recyclerview-v7:22.1.1'

View File

@ -0,0 +1,13 @@
package org.ethereum.android_app;
import android.app.Application;
import android.test.ApplicationTestCase;
/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}

View File

@ -1,17 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.ethereum.android" >
package="org.ethereum.android_app" >
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="org.ethereum.android.EthereumApplication"
android:name="org.ethereum.android_app.EthereumApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme" >
<activity
android:name="org.ethereum.android.MainActivity"
android:name="org.ethereum.android_app.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -19,12 +19,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="org.ethereum.android.MyService"
android:enabled="true"
android:exported="true" >
</service>
</application>
</manifest>

View File

@ -1,68 +0,0 @@
package org.ethereum.android;
import org.ethereum.core.AccountState;
import org.ethereum.core.Denomination;
import org.ethereum.crypto.HashUtil;
import org.spongycastle.util.Arrays;
import org.spongycastle.util.encoders.Hex;
import java.util.List;
/**
* Created by Adrian Tiberius on 06.05.2015.
*/
public class AccountsDataAdapter {
List<DataClass> data;
final String[] columns = new String[]{"Account", "Balance", "Is Contract"};
public AccountsDataAdapter(List<DataClass> data) {
this.data = data;
}
public void addDataPiece(DataClass d) {
data.add(d);
//this.fireTableRowsInserted(Math.min(data.size() - 2, 0), data.size() - 1);
}
public int getRowCount() {
return data.size();
}
public int getColumnCount() {
return 3;
}
public String getColumnName(int column) {
return columns[column];
}
public boolean isCellEditable(int row, int column) { // custom isCellEditable function
return column == 0 ? true : false;
}
public Object getValueAt(int rowIndex, int columnIndex) {
if (columnIndex == 0) {
return Hex.toHexString(data.get(rowIndex).address);
} else if (columnIndex == 1) {
if (data.get(rowIndex).accountState != null) {
return Denomination.toFriendlyString(data.get(rowIndex).accountState.getBalance());
}
return "---";
} else {
if (data.get(rowIndex).accountState != null) {
if (!Arrays.areEqual(data.get(rowIndex).accountState.getCodeHash(), HashUtil.EMPTY_DATA_HASH))
return "Yes";
}
return "No";
}
}
public static class DataClass {
public byte[] address;
public AccountState accountState;
}
}

View File

@ -1,11 +0,0 @@
package org.ethereum.android;
import org.ethereum.core.AccountState;
/**
* Created by userica on 06.05.2015.
*/
public class DataClass {
public byte[] address;
public AccountState accountState;
}

View File

@ -1,82 +0,0 @@
package org.ethereum.android;
import org.ethereum.config.SystemProperties;
import org.ethereum.core.AccountState;
import org.ethereum.facade.Ethereum;
import org.ethereum.facade.Repository;
import org.ethereum.listener.EthereumListenerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Set;
public class EthereumManager {
private static final Logger logger = LoggerFactory.getLogger("manager");
public static Ethereum ethereum = null;
public static AccountsDataAdapter adapter = null;
public static String log = "";
public EthereumManager(Ethereum ethereum) {
this.ethereum = ethereum;
this.addListener();
}
public void start() {
}
public void connect() {
ethereum.connect(SystemProperties.CONFIG.activePeerIP(),
SystemProperties.CONFIG.activePeerPort(),
SystemProperties.CONFIG.activePeerNodeid());
//ethereum.getBlockchain();
}
public void loadAccounts() {
Repository repository = ethereum.getRepository();
Set<byte[]> keys = repository.getAccountsKeys();
for (byte[] key : keys) {
AccountsDataAdapter.DataClass dc = new AccountsDataAdapter.DataClass();
dc.address = key;
AccountState state = repository.getAccountState(dc.address);
dc.accountState = state;
adapter.addDataPiece(dc);
}
}
public void startPeerDiscovery() {
ethereum.startPeerDiscovery();
}
public void addListener() {
ethereum.addListener(new EthereumListenerAdapter() {
@Override
public void trace(final String output) {
logger.info(output);
log += output;
log += "\n\n";
}
});
}
public String getLog() {
String logMessages = EthereumManager.log;
EthereumManager.log = "";
return logMessages;
}
}

View File

@ -1,194 +0,0 @@
package org.ethereum.android;
import android.os.AsyncTask;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.view.View.OnClickListener;
import android.widget.Toast;
import org.ethereum.android.di.components.DaggerEthereumComponent;
import org.ethereum.android.di.modules.EthereumModule;
import org.ethereum.facade.Ethereum;
public class MainActivity extends ActionBarActivity implements OnClickListener, NavigationDrawerCallbacks {
private static final String TAG = "MyActivity";
private static Integer quit = 0;
private TextView text1;
private Button consoleButton;
private Button walletButton;
public EthereumManager ethereumManager = null;
Ethereum ethereum = null;
private NavigationDrawerFragment mNavigationDrawerFragment;
private Toolbar mToolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//this.getApplicationComponent().inject(this);
System.setProperty("sun.arch.data.model", "32");
System.setProperty("leveldb.mmap", "false");
ethereum = DaggerEthereumComponent.builder()
.ethereumModule(new EthereumModule(this))
.build().ethereum();
mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
setSupportActionBar(mToolbar);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.fragment_drawer);
// Set up the drawer.
mNavigationDrawerFragment.setup(R.id.fragment_drawer, (DrawerLayout) findViewById(R.id.drawer), mToolbar);
text1 = (TextView) findViewById(R.id.text1);
text1.setMovementMethod(new ScrollingMovementMethod());
//StrictMode.enableDefaults();
new PostTask().execute(ethereum);
Thread t = new Thread() {
@Override
public void run() {
try {
while (!isInterrupted()) {
Thread.sleep(1000);
runOnUiThread(new Runnable() {
@Override
public void run() {
if (ethereumManager != null) {
text1.append(ethereumManager.getLog());
}
}
});
}
text1.append("XXXXENDXXXX");
quit = 1;
} catch (InterruptedException e) {
}
}
};
t.start();
}
public void onClick(View v) {
switch (v.getId()) {
/*
case R.id.consoleButton: {
// do something for button 1 click
break;
}
*/
//.... etc
}
}
@Override
public void onNavigationDrawerItemSelected(int position) {
// update the main content by replacing fragments
Toast.makeText(this, "Menu item selected -> " + position, Toast.LENGTH_SHORT).show();
}
@Override
public void onBackPressed() {
if (mNavigationDrawerFragment.isDrawerOpen())
mNavigationDrawerFragment.closeDrawer();
else
super.onBackPressed();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (!mNavigationDrawerFragment.isDrawerOpen()) {
// Only show items in the action bar relevant to this screen
// if the drawer is not showing. Otherwise, let the drawer
// decide what to show in the action bar.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
Log.v(TAG, new Integer(id).toString());
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
// The definition of our task class
private class PostTask extends AsyncTask<Ethereum, Integer, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
//displayProgressBar("Downloading...");
}
@Override
protected String doInBackground(Ethereum... params) {
Ethereum ethereum = params[0];
Log.v(TAG, "111");
ethereumManager = new EthereumManager(ethereum);
Log.v(TAG, "222");
ethereumManager.connect();
Log.v(TAG, "333");
//ethereumManager.startPeerDiscovery();
while(true) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (quit == 1) {
//return "All Done!";
}
//publishProgress(1111);
}
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
// updateProgressBar(values[0]);
Log.v(TAG, values[0].toString());
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
//dismissProgressBar();
}
}
}

View File

@ -1,16 +0,0 @@
package org.ethereum.android;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
public class MyService extends Service {
public MyService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
}

View File

@ -1,88 +0,0 @@
package org.ethereum.android;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
public class NavigationDrawerAdapter extends RecyclerView.Adapter<NavigationDrawerAdapter.ViewHolder> {
private List<NavigationItem> mData;
private NavigationDrawerCallbacks mNavigationDrawerCallbacks;
private View mSelectedView;
private int mSelectedPosition;
public NavigationDrawerAdapter(List<NavigationItem> data) {
mData = data;
}
public NavigationDrawerCallbacks getNavigationDrawerCallbacks() {
return mNavigationDrawerCallbacks;
}
public void setNavigationDrawerCallbacks(NavigationDrawerCallbacks navigationDrawerCallbacks) {
mNavigationDrawerCallbacks = navigationDrawerCallbacks;
}
@Override
public NavigationDrawerAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.drawer_row, viewGroup, false);
final ViewHolder viewHolder = new ViewHolder(v);
viewHolder.itemView.setClickable(true);
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mSelectedView != null) {
mSelectedView.setSelected(false);
}
mSelectedPosition = viewHolder.getAdapterPosition();
v.setSelected(true);
mSelectedView = v;
if (mNavigationDrawerCallbacks != null)
mNavigationDrawerCallbacks.onNavigationDrawerItemSelected(viewHolder.getAdapterPosition());
}
}
);
viewHolder.itemView.setBackgroundResource(R.drawable.row_selector);
return viewHolder;
}
@Override
public void onBindViewHolder(NavigationDrawerAdapter.ViewHolder viewHolder, int i) {
viewHolder.textView.setText(mData.get(i).getText());
viewHolder.textView.setCompoundDrawablesWithIntrinsicBounds(mData.get(i).getDrawable(), null, null, null);
if (mSelectedPosition == i) {
if (mSelectedView != null) {
mSelectedView.setSelected(false);
}
mSelectedPosition = i;
mSelectedView = viewHolder.itemView;
mSelectedView.setSelected(true);
}
}
public void selectPosition(int position) {
mSelectedPosition = position;
notifyItemChanged(position);
}
@Override
public int getItemCount() {
return mData != null ? mData.size() : 0;
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView textView;
public ViewHolder(View itemView) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.item_name);
}
}
}

View File

@ -1,5 +0,0 @@
package org.ethereum.android;
public interface NavigationDrawerCallbacks {
void onNavigationDrawerItemSelected(int position);
}

View File

@ -1,219 +0,0 @@
package org.ethereum.android;
import android.app.Activity;
import android.app.Fragment;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.List;
/**
* Fragment used for managing interactions for and presentation of a navigation drawer.
* See the <a href="https://developer.android.com/design/patterns/navigation-drawer.html#Interaction">
* design guidelines</a> for a complete explanation of the behaviors implemented here.
*/
public class NavigationDrawerFragment extends Fragment implements NavigationDrawerCallbacks {
/**
* Remember the position of the selected item.
*/
private static final String STATE_SELECTED_POSITION = "selected_navigation_drawer_position";
/**
* Per the design guidelines, you should show the drawer on launch until the user manually
* expands it. This shared preference tracks this.
*/
private static final String PREF_USER_LEARNED_DRAWER = "navigation_drawer_learned";
/**
* A pointer to the current callbacks instance (the Activity).
*/
private NavigationDrawerCallbacks mCallbacks;
/**
* Helper component that ties the action bar to the navigation drawer.
*/
private ActionBarDrawerToggle mActionBarDrawerToggle;
private DrawerLayout mDrawerLayout;
private RecyclerView mDrawerList;
private View mFragmentContainerView;
private int mCurrentSelectedPosition = 0;
private boolean mFromSavedInstanceState;
private boolean mUserLearnedDrawer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Read in the flag indicating whether or not the user has demonstrated awareness of the
// drawer. See PREF_USER_LEARNED_DRAWER for details.
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity());
mUserLearnedDrawer = sp.getBoolean(PREF_USER_LEARNED_DRAWER, false);
if (savedInstanceState != null) {
mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION);
mFromSavedInstanceState = true;
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
mDrawerList = (RecyclerView) view.findViewById(R.id.drawerList);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
mDrawerList.setLayoutManager(layoutManager);
mDrawerList.setHasFixedSize(true);
final List<NavigationItem> navigationItems = getMenu();
NavigationDrawerAdapter adapter = new NavigationDrawerAdapter(navigationItems);
adapter.setNavigationDrawerCallbacks(this);
mDrawerList.setAdapter(adapter);
selectItem(mCurrentSelectedPosition);
return view;
}
public boolean isDrawerOpen() {
return mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mFragmentContainerView);
}
public ActionBarDrawerToggle getActionBarDrawerToggle() {
return mActionBarDrawerToggle;
}
public DrawerLayout getDrawerLayout() {
return mDrawerLayout;
}
@Override
public void onNavigationDrawerItemSelected(int position) {
selectItem(position);
}
public List<NavigationItem> getMenu() {
List<NavigationItem> items = new ArrayList<NavigationItem>();
items.add(new NavigationItem("Console", getResources().getDrawable(R.drawable.ic_menu_check)));
items.add(new NavigationItem("Peers", getResources().getDrawable(R.drawable.ic_menu_check)));
items.add(new NavigationItem("Block Chain", getResources().getDrawable(R.drawable.ic_menu_check)));
items.add(new NavigationItem("New Transaction", getResources().getDrawable(R.drawable.ic_menu_check)));
items.add(new NavigationItem("Pending Transactions", getResources().getDrawable(R.drawable.ic_menu_check)));
items.add(new NavigationItem("Debug Info", getResources().getDrawable(R.drawable.ic_menu_check)));
return items;
}
/**
* Users of this fragment must call this method to set up the navigation drawer interactions.
*
* @param fragmentId The android:id of this fragment in its activity's layout.
* @param drawerLayout The DrawerLayout containing this fragment's UI.
* @param toolbar The Toolbar of the activity.
*/
public void setup(int fragmentId, DrawerLayout drawerLayout, Toolbar toolbar) {
mFragmentContainerView = getActivity().findViewById(fragmentId);
mDrawerLayout = drawerLayout;
mDrawerLayout.setStatusBarBackgroundColor(getResources().getColor(R.color.myPrimaryDarkColor));
mActionBarDrawerToggle = new ActionBarDrawerToggle(getActivity(), mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) {
@Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
if (!isAdded()) return;
getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
}
@Override
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
if (!isAdded()) return;
if (!mUserLearnedDrawer) {
mUserLearnedDrawer = true;
SharedPreferences sp = PreferenceManager
.getDefaultSharedPreferences(getActivity());
sp.edit().putBoolean(PREF_USER_LEARNED_DRAWER, true).apply();
}
getActivity().invalidateOptionsMenu(); // calls onPrepareOptionsMenu()
}
};
// If the user hasn't 'learned' about the drawer, open it to introduce them to the drawer,
// per the navigation drawer design guidelines.
if (!mUserLearnedDrawer && !mFromSavedInstanceState) {
mDrawerLayout.openDrawer(mFragmentContainerView);
}
// Defer code dependent on restoration of previous instance state.
mDrawerLayout.post(new Runnable() {
@Override
public void run() {
mActionBarDrawerToggle.syncState();
}
});
mDrawerLayout.setDrawerListener(mActionBarDrawerToggle);
}
private void selectItem(int position) {
mCurrentSelectedPosition = position;
if (mDrawerLayout != null) {
mDrawerLayout.closeDrawer(mFragmentContainerView);
}
if (mCallbacks != null) {
mCallbacks.onNavigationDrawerItemSelected(position);
}
((NavigationDrawerAdapter) mDrawerList.getAdapter()).selectPosition(position);
}
public void openDrawer() {
mDrawerLayout.openDrawer(mFragmentContainerView);
}
public void closeDrawer() {
mDrawerLayout.closeDrawer(mFragmentContainerView);
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mCallbacks = (NavigationDrawerCallbacks) activity;
} catch (ClassCastException e) {
throw new ClassCastException("Activity must implement NavigationDrawerCallbacks.");
}
}
@Override
public void onDetach() {
super.onDetach();
mCallbacks = null;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt(STATE_SELECTED_POSITION, mCurrentSelectedPosition);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Forward the new configuration the drawer toggle component.
mActionBarDrawerToggle.onConfigurationChanged(newConfig);
}
}

View File

@ -1,33 +0,0 @@
package org.ethereum.android;
import android.graphics.drawable.Drawable;
/**
* Created by poliveira on 24/10/2014.
*/
public class NavigationItem {
private String mText;
private Drawable mDrawable;
public NavigationItem(String text, Drawable drawable) {
mText = text;
mDrawable = drawable;
}
public String getText() {
return mText;
}
public void setText(String text) {
mText = text;
}
public Drawable getDrawable() {
return mDrawable;
}
public void setDrawable(Drawable drawable) {
mDrawable = drawable;
}
}

View File

@ -1,11 +0,0 @@
package org.ethereum.android.di;
import java.lang.annotation.Retention;
import javax.inject.Scope;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
@Scope
@Retention(RUNTIME)
public @interface PerActivity {}

View File

@ -0,0 +1,48 @@
package org.ethereum.android_app;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.method.ScrollingMovementMethod;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import org.ethereum.listener.EthereumListenerAdapter;
public class ConsoleFragment extends Fragment {
EthereumManager ethereumManager;
private TextView console;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_console, container, false);
console = (TextView) view.findViewById(R.id.console);
console.setMovementMethod(new ScrollingMovementMethod());
console.append("aaaa");
return view;
}
public void setEthereumManager(EthereumManager ethereumManager) {
this.ethereumManager = ethereumManager;
ethereumManager.addListener(new EthereumListenerAdapter() {
@Override
public void trace(final String output) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
console.append(output);
}
});
}
});
}
}

View File

@ -1,4 +1,4 @@
package org.ethereum.android;
package org.ethereum.android_app;
import android.support.multidex.MultiDexApplication;

View File

@ -0,0 +1,116 @@
package org.ethereum.android_app;
import android.content.Context;
import android.os.AsyncTask;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends ActionBarActivity {
private static final String TAG = "MyActivity";
private static Integer quit = 0;
private Toolbar toolbar;
private ViewPager viewPager;
private SlidingTabLayout tabs;
private TabsPagerAdapter adapter;
public EthereumManager ethereumManager = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.tool_bar);
setSupportActionBar(toolbar);
ethereumManager = new EthereumManager(this);
adapter = new TabsPagerAdapter(getSupportFragmentManager(), ethereumManager);
viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(adapter);;
tabs = (SlidingTabLayout) findViewById(R.id.tabs);
tabs.setDistributeEvenly(true);
tabs.setViewPager(viewPager);
//StrictMode.enableDefaults();
new PostTask().execute();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
//return super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
Log.v(TAG, new Integer(id).toString());
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
// The definition of our task class
private class PostTask extends AsyncTask<Context, Integer, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(Context... params) {
Log.v(TAG, "111");
Log.v(TAG, "222");
ethereumManager.connect();
Log.v(TAG, "333");
while(true) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (quit == 1) {
Log.v(TAG, "Ending background process.");
return "All Done!";
}
//publishProgress(1111);
}
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
Log.v(TAG, values[0].toString());
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
}
}
}

View File

@ -0,0 +1,291 @@
package org.ethereum.android_app;
import android.content.Context;
import android.graphics.Typeface;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.TextView;
public class SlidingTabLayout extends HorizontalScrollView {
/**
* Allows complete control over the colors drawn in the tab layout. Set with
* {@link #setCustomTabColorizer(TabColorizer)}.
*/
public interface TabColorizer {
int getIndicatorColor(int position);
}
private static final int TITLE_OFFSET_DIPS = 24;
private static final int TAB_VIEW_PADDING_DIPS = 16;
private static final int TAB_VIEW_TEXT_SIZE_SP = 12;
private int mTitleOffset;
private int mTabViewLayoutId;
private int mTabViewTextViewId;
private boolean mDistributeEvenly;
private ViewPager mViewPager;
private SparseArray<String> mContentDescriptions = new SparseArray<String>();
private ViewPager.OnPageChangeListener mViewPagerPageChangeListener;
private final SlidingTabStrip mTabStrip;
public SlidingTabLayout(Context context) {
this(context, null);
}
public SlidingTabLayout(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// Disable the Scroll Bar
setHorizontalScrollBarEnabled(false);
// Make sure that the Tab Strips fills this View
setFillViewport(true);
mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);
mTabStrip = new SlidingTabStrip(context);
addView(mTabStrip, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
}
/**
* Set the custom {@link TabColorizer} to be used.
*
* If you only require simple custmisation then you can use
* {@link #setSelectedIndicatorColors(int...)} to achieve
* similar effects.
*/
public void setCustomTabColorizer(TabColorizer tabColorizer) {
mTabStrip.setCustomTabColorizer(tabColorizer);
}
public void setDistributeEvenly(boolean distributeEvenly) {
mDistributeEvenly = distributeEvenly;
}
/**
* Sets the colors to be used for indicating the selected tab. These colors are treated as a
* circular array. Providing one color will mean that all tabs are indicated with the same color.
*/
public void setSelectedIndicatorColors(int... colors) {
mTabStrip.setSelectedIndicatorColors(colors);
}
/**
* Set the {@link ViewPager.OnPageChangeListener}. When using {@link SlidingTabLayout} you are
* required to set any {@link ViewPager.OnPageChangeListener} through this method. This is so
* that the layout can update it's scroll position correctly.
*
* @see ViewPager#setOnPageChangeListener(ViewPager.OnPageChangeListener)
*/
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
mViewPagerPageChangeListener = listener;
}
/**
* Set the custom layout to be inflated for the tab views.
*
* @param layoutResId Layout id to be inflated
* @param textViewId id of the {@link TextView} in the inflated view
*/
public void setCustomTabView(int layoutResId, int textViewId) {
mTabViewLayoutId = layoutResId;
mTabViewTextViewId = textViewId;
}
/**
* Sets the associated view pager. Note that the assumption here is that the pager content
* (number of tabs and tab titles) does not change after this call has been made.
*/
public void setViewPager(ViewPager viewPager) {
mTabStrip.removeAllViews();
mViewPager = viewPager;
if (viewPager != null) {
viewPager.setOnPageChangeListener(new InternalViewPagerListener());
populateTabStrip();
}
}
/**
* Create a default view to be used for tabs. This is called if a custom tab view is not set via
* {@link #setCustomTabView(int, int)}.
*/
protected TextView createDefaultTabView(Context context) {
TextView textView = new TextView(context);
textView.setGravity(Gravity.CENTER);
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
textView.setTypeface(Typeface.DEFAULT_BOLD);
textView.setLayoutParams(new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
TypedValue outValue = new TypedValue();
getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
outValue, true);
textView.setBackgroundResource(outValue.resourceId);
textView.setAllCaps(true);
int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
textView.setPadding(padding, padding, padding, padding);
return textView;
}
private void populateTabStrip() {
final PagerAdapter adapter = mViewPager.getAdapter();
final View.OnClickListener tabClickListener = new TabClickListener();
for (int i = 0; i < adapter.getCount(); i++) {
View tabView = null;
TextView tabTitleView = null;
if (mTabViewLayoutId != 0) {
// If there is a custom tab view layout id set, try and inflate it
tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip,
false);
tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
}
if (tabView == null) {
tabView = createDefaultTabView(getContext());
}
if (tabTitleView == null && TextView.class.isInstance(tabView)) {
tabTitleView = (TextView) tabView;
}
if (mDistributeEvenly) {
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
lp.width = 0;
lp.weight = 1;
}
tabTitleView.setText(adapter.getPageTitle(i));
tabView.setOnClickListener(tabClickListener);
String desc = mContentDescriptions.get(i, null);
if (desc != null) {
tabView.setContentDescription(desc);
}
mTabStrip.addView(tabView);
if (i == mViewPager.getCurrentItem()) {
tabView.setSelected(true);
}
tabTitleView.setTextSize(14);
}
}
public void setContentDescription(int i, String desc) {
mContentDescriptions.put(i, desc);
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (mViewPager != null) {
scrollToTab(mViewPager.getCurrentItem(), 0);
}
}
private void scrollToTab(int tabIndex, int positionOffset) {
final int tabStripChildCount = mTabStrip.getChildCount();
if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) {
return;
}
View selectedChild = mTabStrip.getChildAt(tabIndex);
if (selectedChild != null) {
int targetScrollX = selectedChild.getLeft() + positionOffset;
if (tabIndex > 0 || positionOffset > 0) {
// If we're not at the first child and are mid-scroll, make sure we obey the offset
targetScrollX -= mTitleOffset;
}
scrollTo(targetScrollX, 0);
}
}
private class InternalViewPagerListener implements ViewPager.OnPageChangeListener {
private int mScrollState;
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
int tabStripChildCount = mTabStrip.getChildCount();
if ((tabStripChildCount == 0) || (position < 0) || (position >= tabStripChildCount)) {
return;
}
mTabStrip.onViewPagerPageChanged(position, positionOffset);
View selectedTitle = mTabStrip.getChildAt(position);
int extraOffset = (selectedTitle != null)
? (int) (positionOffset * selectedTitle.getWidth())
: 0;
scrollToTab(position, extraOffset);
if (mViewPagerPageChangeListener != null) {
mViewPagerPageChangeListener.onPageScrolled(position, positionOffset,
positionOffsetPixels);
}
}
@Override
public void onPageScrollStateChanged(int state) {
mScrollState = state;
if (mViewPagerPageChangeListener != null) {
mViewPagerPageChangeListener.onPageScrollStateChanged(state);
}
}
@Override
public void onPageSelected(int position) {
if (mScrollState == ViewPager.SCROLL_STATE_IDLE) {
mTabStrip.onViewPagerPageChanged(position, 0f);
scrollToTab(position, 0);
}
for (int i = 0; i < mTabStrip.getChildCount(); i++) {
mTabStrip.getChildAt(i).setSelected(position == i);
}
if (mViewPagerPageChangeListener != null) {
mViewPagerPageChangeListener.onPageSelected(position);
}
}
}
private class TabClickListener implements View.OnClickListener {
@Override
public void onClick(View v) {
for (int i = 0; i < mTabStrip.getChildCount(); i++) {
if (v == mTabStrip.getChildAt(i)) {
mViewPager.setCurrentItem(i);
return;
}
}
}
}
}

View File

@ -0,0 +1,152 @@
package org.ethereum.android_app;
import android.R;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.LinearLayout;
class SlidingTabStrip extends LinearLayout {
private static final int DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS = 0;
private static final byte DEFAULT_BOTTOM_BORDER_COLOR_ALPHA = 0x26;
private static final int SELECTED_INDICATOR_THICKNESS_DIPS = 3;
private static final int DEFAULT_SELECTED_INDICATOR_COLOR = 0xFF33B5E5;
private final int mBottomBorderThickness;
private final Paint mBottomBorderPaint;
private final int mSelectedIndicatorThickness;
private final Paint mSelectedIndicatorPaint;
private final int mDefaultBottomBorderColor;
private int mSelectedPosition;
private float mSelectionOffset;
private SlidingTabLayout.TabColorizer mCustomTabColorizer;
private final SimpleTabColorizer mDefaultTabColorizer;
SlidingTabStrip(Context context) {
this(context, null);
}
SlidingTabStrip(Context context, AttributeSet attrs) {
super(context, attrs);
setWillNotDraw(false);
final float density = getResources().getDisplayMetrics().density;
TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(R.attr.colorForeground, outValue, true);
final int themeForegroundColor = outValue.data;
mDefaultBottomBorderColor = setColorAlpha(themeForegroundColor,
DEFAULT_BOTTOM_BORDER_COLOR_ALPHA);
mDefaultTabColorizer = new SimpleTabColorizer();
mDefaultTabColorizer.setIndicatorColors(DEFAULT_SELECTED_INDICATOR_COLOR);
mBottomBorderThickness = (int) (DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS * density);
mBottomBorderPaint = new Paint();
mBottomBorderPaint.setColor(mDefaultBottomBorderColor);
mSelectedIndicatorThickness = (int) (SELECTED_INDICATOR_THICKNESS_DIPS * density);
mSelectedIndicatorPaint = new Paint();
}
void setCustomTabColorizer(SlidingTabLayout.TabColorizer customTabColorizer) {
mCustomTabColorizer = customTabColorizer;
invalidate();
}
void setSelectedIndicatorColors(int... colors) {
// Make sure that the custom colorizer is removed
mCustomTabColorizer = null;
mDefaultTabColorizer.setIndicatorColors(colors);
invalidate();
}
void onViewPagerPageChanged(int position, float positionOffset) {
mSelectedPosition = position;
mSelectionOffset = positionOffset;
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
final int height = getHeight();
final int childCount = getChildCount();
final SlidingTabLayout.TabColorizer tabColorizer = mCustomTabColorizer != null
? mCustomTabColorizer
: mDefaultTabColorizer;
// Thick colored underline below the current selection
if (childCount > 0) {
View selectedTitle = getChildAt(mSelectedPosition);
int left = selectedTitle.getLeft();
int right = selectedTitle.getRight();
int color = tabColorizer.getIndicatorColor(mSelectedPosition);
if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) {
int nextColor = tabColorizer.getIndicatorColor(mSelectedPosition + 1);
if (color != nextColor) {
color = blendColors(nextColor, color, mSelectionOffset);
}
// Draw the selection partway between the tabs
View nextTitle = getChildAt(mSelectedPosition + 1);
left = (int) (mSelectionOffset * nextTitle.getLeft() +
(1.0f - mSelectionOffset) * left);
right = (int) (mSelectionOffset * nextTitle.getRight() +
(1.0f - mSelectionOffset) * right);
}
mSelectedIndicatorPaint.setColor(color);
canvas.drawRect(left, height - mSelectedIndicatorThickness, right,
height, mSelectedIndicatorPaint);
}
// Thin underline along the entire bottom edge
canvas.drawRect(0, height - mBottomBorderThickness, getWidth(), height, mBottomBorderPaint);
}
/**
* Set the alpha value of the {@code color} to be the given {@code alpha} value.
*/
private static int setColorAlpha(int color, byte alpha) {
return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color));
}
/**
* Blend {@code color1} and {@code color2} using the given ratio.
*
* @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend,
* 0.0 will return {@code color2}.
*/
private static int blendColors(int color1, int color2, float ratio) {
final float inverseRation = 1f - ratio;
float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
return Color.rgb((int) r, (int) g, (int) b);
}
private static class SimpleTabColorizer implements SlidingTabLayout.TabColorizer {
private int[] mIndicatorColors;
@Override
public final int getIndicatorColor(int position) {
return mIndicatorColors[position % mIndicatorColors.length];
}
void setIndicatorColors(int... colors) {
mIndicatorColors = colors;
}
}
}

View File

@ -0,0 +1,48 @@
package org.ethereum.android_app;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
public class TabsPagerAdapter extends FragmentPagerAdapter {
int tabsCount;
private String[] tabTitles = { "Console", "Tests" };
private EthereumManager ethereumManager;
public TabsPagerAdapter(FragmentManager fragmentManager, EthereumManager ethereumManager) {
super(fragmentManager);
this.tabsCount = tabTitles.length;
this.ethereumManager = ethereumManager;
}
@Override
public Fragment getItem(int index) {
switch (index) {
case 0:
ConsoleFragment consoleFragment = new ConsoleFragment();
consoleFragment.setEthereumManager(ethereumManager);
return consoleFragment;
case 1:
TestsFragment testsFragment = new TestsFragment();
return testsFragment;
}
return null;
}
@Override
public CharSequence getPageTitle(int position) {
return tabTitles[position];
}
@Override
public int getCount() {
return tabsCount;
}
}

View File

@ -0,0 +1,20 @@
package org.ethereum.android_app;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class TestsFragment extends Fragment {
EthereumManager ethereumManager;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_tests, container, false);
return view;
}
}

View File

@ -1,30 +1,28 @@
<RelativeLayout 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=".MainActivity">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<include android:id="@+id/toolbar_actionbar" layout="@layout/toolbar_default"
android:layout_width="match_parent" android:layout_height="wrap_content" />
<include
android:id="@+id/tool_bar"
layout="@layout/toolbar_default"
android:layout_height="wrap_content"
android:layout_width="match_parent"
/>
<android.support.v4.widget.DrawerLayout android:id="@+id/drawer"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_below="@+id/toolbar_actionbar">
<org.ethereum.android_app.SlidingTabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="2dp"/>
<FrameLayout android:id="@+id/container" android:layout_width="match_parent"
android:clickable="true" android:layout_height="match_parent" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_weight="1">
</android.support.v4.view.ViewPager>
<!-- android:layout_marginTop="?android:attr/actionBarSize"-->
<fragment android:id="@+id/fragment_drawer"
android:name="org.ethereum.android.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent" android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:scrollbars = "vertical" android:gravity="bottom"
android:fontFamily="Arial" android:typeface="serif" android:textSize="8sp"
android:id="@+id/text1" android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>

View File

@ -1,9 +0,0 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="48dp" android:layout_width="match_parent">
<TextView android:id="@+id/item_name" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/selectableItemBackground" android:drawablePadding="16dp"
android:textSize="14sp" android:gravity="center_vertical"
android:textColor="@color/myTextPrimaryColor" />
</LinearLayout>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:text="Console Output:"
android:textSize="14dp"
android:layout_centerInParent="true"
android:id="@+id/console"/>
</RelativeLayout>

View File

@ -1,5 +0,0 @@
<android.support.v7.widget.RecyclerView android:id="@+id/drawerList"
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:clickable="true" android:scrollbars="vertical"
android:layout_height="match_parent" android:background="@color/myDrawerBackground" />

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="EthereumJ Tests"
android:textSize="20dp"
android:layout_centerInParent="true"/>
</RelativeLayout>

View File

@ -1,4 +1,7 @@
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/ToolBarStyle" android:layout_width="match_parent"
android:layout_height="wrap_content" android:background="?attr/colorPrimary"
android:minHeight="@dimen/abc_action_bar_default_height_material" />
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:elevation="2dp"
android:theme="@style/Base.ThemeOverlay.AppCompat.Dark"
xmlns:android="http://schemas.android.com/apk/res/android" />

View File

@ -1,10 +1,10 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
allprojects {
repositories {
maven {
url "https://oss.sonatype.org/content/repositories/snapshots"
}
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.0'
}
}
}

View File

@ -0,0 +1,50 @@
package org.ethereum.android;
import android.content.Context;
import org.ethereum.android.di.components.DaggerEthereumComponent;
import org.ethereum.android.di.modules.EthereumModule;
import org.ethereum.config.SystemProperties;
import org.ethereum.facade.Ethereum;
import org.ethereum.listener.EthereumListenerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class EthereumManager {
private static final Logger logger = LoggerFactory.getLogger("manager");
public static Ethereum ethereum = null;
public EthereumManager(Context context) {
System.setProperty("sun.arch.data.model", "32");
System.setProperty("leveldb.mmap", "false");
ethereum = DaggerEthereumComponent.builder()
.ethereumModule(new EthereumModule(context))
.build().ethereum();
}
public void start() {
}
public void connect() {
ethereum.connect(SystemProperties.CONFIG.activePeerIP(),
SystemProperties.CONFIG.activePeerPort(),
SystemProperties.CONFIG.activePeerNodeid());
//ethereum.getBlockchain();
}
public void startPeerDiscovery() {
ethereum.startPeerDiscovery();
}
public void addListener(EthereumListenerAdapter listener) {
ethereum.addListener(listener);
}
}

View File

@ -69,7 +69,7 @@ public class LevelDbDataSource implements KeyValueDataSource {
}
logger.debug("Initializing new or existing database: '{}'", fileLocation.getAbsolutePath());
db = factory.open(fileLocation, options);
db = Iq80DBFactory.factory.open(fileLocation, options);
} catch (IOException ioe) {
logger.error(ioe.getMessage(), ioe);
@ -82,7 +82,7 @@ public class LevelDbDataSource implements KeyValueDataSource {
logger.debug("Destroying existing database");
Options options = new Options();
try {
factory.destroy(fileLocation, options);
Iq80DBFactory.factory.destroy(fileLocation, options);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}

1
ethereumj-core-android/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

View File

@ -0,0 +1,47 @@
apply plugin: 'com.android.library'
apply plugin: 'com.neenbedankt.android-apt'
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
repositories {
jcenter()
mavenCentral()
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
apt 'com.google.dagger:dagger-compiler:2.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':ethereumj-core')
compile "com.google.dagger:dagger:2.1-SNAPSHOT"
compile "com.j256.ormlite:ormlite-android:4.48"
compile "org.glassfish:javax.annotation:10.0-b28"
compile "org.iq80.leveldb:leveldb:0.7"
}

View File

@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/userica/Android/Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

View File

@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.ethereum.android">
<application android:allowBackup="true" android:label="@string/app_name">
</application>
</manifest>

View File

@ -0,0 +1,50 @@
package org.ethereum.android;
import android.content.Context;
import org.ethereum.android.di.modules.EthereumModule;
import org.ethereum.android.di.components.DaggerEthereumComponent;
import org.ethereum.config.SystemProperties;
import org.ethereum.facade.Ethereum;
import org.ethereum.listener.EthereumListenerAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class EthereumManager {
private static final Logger logger = LoggerFactory.getLogger("manager");
public static Ethereum ethereum = null;
public EthereumManager(Context context) {
System.setProperty("sun.arch.data.model", "32");
System.setProperty("leveldb.mmap", "false");
ethereum = DaggerEthereumComponent.builder()
.ethereumModule(new EthereumModule(context))
.build().ethereum();
}
public void start() {
}
public void connect() {
ethereum.connect(SystemProperties.CONFIG.activePeerIP(),
SystemProperties.CONFIG.activePeerPort(),
SystemProperties.CONFIG.activePeerNodeid());
//ethereum.getBlockchain();
}
public void startPeerDiscovery() {
ethereum.startPeerDiscovery();
}
public void addListener(EthereumListenerAdapter listener) {
ethereum.addListener(listener);
}
}

View File

@ -0,0 +1,146 @@
package org.ethereum.android.datasource;
import org.ethereum.config.SystemProperties;
import org.ethereum.datasource.KeyValueDataSource;
import org.iq80.leveldb.CompressionType;
import org.iq80.leveldb.DB;
import org.iq80.leveldb.DBIterator;
import org.iq80.leveldb.Options;
import org.iq80.leveldb.WriteBatch;
import org.iq80.leveldb.impl.Iq80DBFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import android.content.Context;
/**
* @author Roman Mandeleil
* @since 18.01.2015
*/
public class LevelDbDataSource implements KeyValueDataSource {
private static final Logger logger = LoggerFactory.getLogger("db");
String name;
private DB db;
private Context context;
public LevelDbDataSource() {
}
public LevelDbDataSource(String name) {
this.name = name;
}
public void setContext(Context context) {
this.context = context;
}
@Override
public void init() {
if (name == null) throw new NullPointerException("no name set to the db");
Options options = new Options();
options.createIfMissing(true);
options.compressionType(CompressionType.NONE);
org.iq80.leveldb.Logger logger1 = new org.iq80.leveldb.Logger() {
public void log(String message) {
logger.debug(message);
}
};
options.logger(logger1);
try {
logger.debug("Opening database");
File dbLocation = context.getDir(SystemProperties.CONFIG.databaseDir(), 0);
File fileLocation = new File(dbLocation, name);
if (SystemProperties.CONFIG.databaseReset()) {
destroyDB(fileLocation);
}
logger.debug("Initializing new or existing database: '{}'", fileLocation.getAbsolutePath());
db = Iq80DBFactory.factory.open(fileLocation, options);
} catch (IOException ioe) {
logger.error(ioe.getMessage(), ioe);
throw new RuntimeException("Can't initialize database");
}
}
public void destroyDB(File fileLocation) {
logger.debug("Destroying existing database");
Options options = new Options();
try {
Iq80DBFactory.factory.destroy(fileLocation, options);
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
@Override
public void setName(String name) {
this.name = name;
}
@Override
public byte[] get(byte[] key) {
return db.get(key);
}
@Override
public byte[] put(byte[] key, byte[] value) {
db.put(key, value);
return value;
}
@Override
public void delete(byte[] key) {
db.delete(key);
}
@Override
public Set<byte[]> keys() {
DBIterator dbIterator = db.iterator();
Set<byte[]> keys = new HashSet<>();
while (dbIterator.hasNext()) {
Map.Entry<byte[], byte[]> entry = dbIterator.next();
keys.add(entry.getKey());
}
return keys;
}
@Override
public void updateBatch(Map<byte[], byte[]> rows) {
WriteBatch batch = db.createWriteBatch();
for (Map.Entry<byte[], byte[]> row : rows.entrySet())
batch.put(row.getKey(), row.getValue());
db.write(batch);
}
@Override
public void close() {
try {
logger.info("Close db: {}", name);
db.close();
} catch (IOException e) {
logger.error("Failed to find the db file on the close: {} ", name);
}
}
}

View File

@ -0,0 +1,84 @@
package org.ethereum.android.db;
import java.sql.SQLException;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import org.ethereum.db.BlockVO;
/**
* Database helper class used to manage the creation and upgrading of your database. This class also usually provides
* the DAOs used by the other classes.
*/
public class BlockDatabaseHelper extends OrmLiteSqliteOpenHelper {
private static final String DATABASE_NAME = "blocks.db";
private static final int DATABASE_VERSION = 1;
// the DAO object we use to access the SimpleData table
private Dao<BlockVO, Integer> blockDao = null;
public BlockDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
/**
* This is called when the database is first created. Usually you should call createTable statements here to create
* the tables that will store your data.
*/
@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
try {
Log.i(BlockDatabaseHelper.class.getName(), "onCreate");
TableUtils.createTable(connectionSource, BlockVO.class);
} catch (SQLException e) {
Log.e(BlockDatabaseHelper.class.getName(), "Can't create database", e);
throw new RuntimeException(e);
}
}
/**
* This is called when your application is upgraded and it has a higher version number. This allows you to adjust
* the various data to match the new version number.
*/
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
try {
Log.i(BlockDatabaseHelper.class.getName(), "onUpgrade");
TableUtils.dropTable(connectionSource, BlockVO.class, true);
// after we drop the old databases, we create the new ones
onCreate(db, connectionSource);
} catch (SQLException e) {
Log.e(BlockDatabaseHelper.class.getName(), "Can't drop databases", e);
throw new RuntimeException(e);
}
}
/**
* Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached
* value.
*/
public Dao<BlockVO, Integer> getBlockDao() throws SQLException {
if (blockDao == null) {
blockDao = getDao(BlockVO.class);
}
return blockDao;
}
/**
* Close the database connections and clear any cached DAOs.
*/
@Override
public void close() {
super.close();
blockDao = null;
}
}

View File

@ -0,0 +1,93 @@
package org.ethereum.android.db;
import org.ethereum.core.Block;
import org.ethereum.core.TransactionReceipt;
import org.ethereum.db.BlockStore;
import org.ethereum.util.ByteUtil;
import java.math.BigInteger;
import java.util.List;
public class BlockStoreImpl implements BlockStore {
private BlockDatabaseHelper blockDao;
private TransactionDatabaseHelper transactionDao;
public BlockStoreImpl(BlockDatabaseHelper blockDao, TransactionDatabaseHelper transactionDao) {
this.blockDao = blockDao;
this.transactionDao = transactionDao;
}
public byte[] getBlockHashByNumber(long blockNumber) {
Block block = getBlockByNumber(blockNumber);
if (block != null) return block.getHash();
return ByteUtil.EMPTY_BYTE_ARRAY;
}
public Block getBlockByNumber(long blockNumber) {
/*
List result = sessionFactory.getCurrentSession().
createQuery("from BlockVO where number = :number").
setParameter("number", blockNumber).list();
if (result.size() == 0) return null;
BlockVO vo = (BlockVO) result.get(0);
return new Block(vo.rlp);
*/
return null;
}
public Block getBlockByHash(byte[] hash) {
return null;
}
@SuppressWarnings("unchecked")
public List<byte[]> getListOfHashesStartFrom(byte[] hash, int qty) {
return null;
}
public void deleteBlocksSince(long number) {
}
public void saveBlock(Block block, List<TransactionReceipt> receipts) {
}
public BigInteger getTotalDifficultySince(long number) {
return null;
}
public BigInteger getTotalDifficulty() {
return null;
}
public Block getBestBlock() {
return null;
}
@SuppressWarnings("unchecked")
public List<Block> getAllBlocks() {
return null;
}
public void reset() {
}
public TransactionReceipt getTransactionReceiptByHash(byte[] hash) {
return null;
}
}

View File

@ -0,0 +1,84 @@
package org.ethereum.android.db;
import java.sql.SQLException;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import org.ethereum.db.TransactionReceiptVO;
/**
* Database helper class used to manage the creation and upgrading of your database. This class also usually provides
* the DAOs used by the other classes.
*/
public class TransactionDatabaseHelper extends OrmLiteSqliteOpenHelper {
private static final String DATABASE_NAME = "transactions.db";
private static final int DATABASE_VERSION = 1;
// the DAO object we use to access the SimpleData table
private Dao<TransactionReceiptVO, Integer> dao = null;
public TransactionDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
/**
* This is called when the database is first created. Usually you should call createTable statements here to create
* the tables that will store your data.
*/
@Override
public void onCreate(SQLiteDatabase db, ConnectionSource connectionSource) {
try {
Log.i(BlockDatabaseHelper.class.getName(), "onCreate");
TableUtils.createTable(connectionSource, TransactionReceiptVO.class);
} catch (SQLException e) {
Log.e(BlockDatabaseHelper.class.getName(), "Can't create database", e);
throw new RuntimeException(e);
}
}
/**
* This is called when your application is upgraded and it has a higher version number. This allows you to adjust
* the various data to match the new version number.
*/
@Override
public void onUpgrade(SQLiteDatabase db, ConnectionSource connectionSource, int oldVersion, int newVersion) {
try {
Log.i(BlockDatabaseHelper.class.getName(), "onUpgrade");
TableUtils.dropTable(connectionSource, TransactionReceiptVO.class, true);
// after we drop the old databases, we create the new ones
onCreate(db, connectionSource);
} catch (SQLException e) {
Log.e(BlockDatabaseHelper.class.getName(), "Can't drop databases", e);
throw new RuntimeException(e);
}
}
/**
* Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached
* value.
*/
public Dao<TransactionReceiptVO, Integer> getBlockDao() throws SQLException {
if (dao == null) {
dao = getDao(TransactionReceiptVO.class);
}
return dao;
}
/**
* Close the database connections and clear any cached DAOs.
*/
@Override
public void close() {
super.close();
dao = null;
}
}

View File

@ -0,0 +1,18 @@
package org.ethereum.android.di.components;
import android.content.Context;
import org.ethereum.android.di.modules.EthereumModule;
import org.ethereum.facade.Ethereum;
import javax.inject.Singleton;
import dagger.Component;
@Singleton
@Component(modules = EthereumModule.class)
public interface EthereumComponent {
Context context();
Ethereum ethereum();
}

View File

@ -0,0 +1,170 @@
package org.ethereum.android.di.modules;
import android.content.Context;
import org.ethereum.android.datasource.LevelDbDataSource;
import org.ethereum.config.SystemProperties;
import org.ethereum.core.BlockchainImpl;
import org.ethereum.core.Wallet;
import org.ethereum.db.BlockStore;
import org.ethereum.db.InMemoryBlockStore;
import org.ethereum.db.RepositoryImpl;
import org.ethereum.facade.Blockchain;
import org.ethereum.facade.Ethereum;
import org.ethereum.facade.EthereumImpl;
import org.ethereum.facade.Repository;
import org.ethereum.listener.CompositeEthereumListener;
import org.ethereum.listener.EthereumListener;
import org.ethereum.manager.AdminInfo;
import org.ethereum.manager.BlockLoader;
import org.ethereum.manager.WorldManager;
import org.ethereum.net.MessageQueue;
import org.ethereum.net.client.PeerClient;
import org.ethereum.net.eth.EthHandler;
import org.ethereum.net.p2p.P2pHandler;
import org.ethereum.net.peerdiscovery.DiscoveryChannel;
import org.ethereum.net.peerdiscovery.PeerDiscovery;
import org.ethereum.net.peerdiscovery.WorkerThread;
import org.ethereum.net.server.ChannelManager;
import org.ethereum.net.server.EthereumChannelInitializer;
import org.ethereum.net.shh.ShhHandler;
import org.ethereum.net.wire.MessageCodec;
import org.ethereum.vm.ProgramInvokeFactory;
import org.ethereum.vm.ProgramInvokeFactoryImpl;
import javax.inject.Provider;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
@Module
public class EthereumModule {
private Context context;
public EthereumModule(Context context) {
this.context = context;
}
@Provides
@Singleton
Ethereum provideEthereum(WorldManager worldManager, AdminInfo adminInfo, ChannelManager channelManager,
BlockLoader blockLoader, Provider<PeerClient> peerClientProvider, EthereumListener listener) {
return new EthereumImpl(worldManager, adminInfo, channelManager, blockLoader, peerClientProvider, listener);
}
@Provides
@Singleton
WorldManager provideWorldManager(Blockchain blockchain, Repository repository, Wallet wallet, PeerDiscovery peerDiscovery
,BlockStore blockStore, ChannelManager channelManager, AdminInfo adminInfo, EthereumListener listener) {
return new WorldManager(blockchain, repository, wallet, peerDiscovery, blockStore, channelManager, adminInfo, listener);
}
@Provides
@Singleton
Blockchain provideBlockchain(BlockStore blockStore, Repository repository,
Wallet wallet, AdminInfo adminInfo,
EthereumListener listener, ChannelManager channelManager) {
return new BlockchainImpl(blockStore, repository, wallet, adminInfo, listener, channelManager);
}
@Provides
@Singleton
BlockStore provideBlockStore() {
return new InMemoryBlockStore();
}
@Provides
@Singleton
Repository provideRepository() {
LevelDbDataSource detailsDS = new LevelDbDataSource();
detailsDS.setContext(context);
LevelDbDataSource stateDS = new LevelDbDataSource();
stateDS.setContext(context);
return new RepositoryImpl(detailsDS, stateDS);
}
@Provides
@Singleton
AdminInfo provideAdminInfo() {
return new AdminInfo();
}
@Provides
@Singleton
EthereumListener provideEthereumListener() {
return new CompositeEthereumListener();
}
@Provides
@Singleton
PeerDiscovery providePeerDiscovery() {
return new PeerDiscovery();
}
@Provides
@Singleton
ChannelManager provideChannelManager(EthereumListener listener) {
return new ChannelManager(listener);
}
@Provides
@Singleton
BlockLoader provideBlockLoader(Blockchain blockchain) {
return new BlockLoader(blockchain);
}
@Provides
@Singleton
ProgramInvokeFactory provideProgramInvokeFactory() {
return new ProgramInvokeFactoryImpl();
}
@Provides
EthHandler provideEthHandler(Blockchain blockchain, EthereumListener listener, Wallet wallet) {
return new EthHandler(blockchain, listener, wallet);
}
@Provides
ShhHandler provideShhHandler(EthereumListener listener) {
return new ShhHandler(listener);
}
@Provides
P2pHandler provideP2pHandler(PeerDiscovery peerDiscovery, EthereumListener listener) {
return new P2pHandler(peerDiscovery, listener);
}
@Provides
MessageCodec provideMessageCodec(EthereumListener listener) {
return new MessageCodec(listener);
}
@Provides
PeerClient providePeerClient(EthereumListener listener, ChannelManager channelManager,
Provider<EthereumChannelInitializer> ethereumChannelInitializerProvider) {
return new PeerClient(listener, channelManager, ethereumChannelInitializerProvider);
}
@Provides
MessageQueue provideMessageQueue(EthereumListener listener) {
return new MessageQueue(listener);
}
@Provides
WorkerThread provideWorkerThread(Provider<DiscoveryChannel> discoveryChannelProvider) {
return new WorkerThread(discoveryChannelProvider);
}
@Provides
String provideRemoteId() {
return SystemProperties.CONFIG.activePeerNodeid();
}
@Provides
@Singleton
Context provideContext() {
return context;
}
}

View File

@ -0,0 +1,3 @@
<resources>
<string name="app_name">ethereum-core-android</string>
</resources>

View File

@ -1,5 +1,5 @@
apply plugin: 'com.android.library'
apply plugin: 'com.neenbedankt.android-apt'
//apply plugin: 'com.android.library'
//apply plugin: 'com.neenbedankt.android-apt'
buildscript {
repositories {
@ -11,12 +11,30 @@ buildscript {
}
dependencies {
classpath 'me.champeau.gradle:antlr4-gradle-plugin:0.1'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.0.1'
// classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
}
apply plugin: 'me.champeau.gradle.antlr4'
plugins {
id 'application'
id 'jacoco'
//id 'com.github.johnrengelman.shadow' version '1.2.0'
id 'me.champeau.gradle.antlr4' version '0.1'
id 'com.github.kt3k.coveralls' version '2.0.1x'
id 'com.jfrog.bintray' version '1.0'
}
apply plugin: 'com.jfrog.artifactory-upload'
sourceCompatibility = 1.7
mainClassName = 'org.ethereum.Start'
configurations {
compile.extendsFrom antlr4
provided
}
repositories {
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
@ -31,45 +49,6 @@ repositories {
ext.generatedSrcDir = file('src/gen/java')
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
// TODO remove this later
lintOptions {
abortOnError false
}
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
java {
exclude '**/BlockStoreImpl.java'
exclude '**/CommonConfig.java'
exclude '**/DefaultConfig.java'
exclude '**/RemoteConfig.java'
exclude '**/EthereumFactory.java'
exclude '**/Start.java'
srcDirs += generatedSrcDir
}
}
}
}
antlr4 {
extraArgs = ['-package', 'org.ethereum.serpent']
output = file("${generatedSrcDir}/org/ethereum/serpent")
@ -90,11 +69,26 @@ ext {
junitVersion = '4.11'
}
sourceSets {
main {
java {
exclude '**/BlockStoreImpl.java'
exclude '**/CommonConfig.java'
exclude '**/DefaultConfig.java'
exclude '**/RemoteConfig.java'
exclude '**/EthereumFactory.java'
exclude '**/Start.java'
srcDirs += generatedSrcDir
}
}
}
dependencies {
apt 'com.google.dagger:dagger-compiler:2.0'
compile 'com.google.dagger:dagger-compiler:2.0'
compile 'com.google.dagger:dagger:2.0'
compile fileTree(include: ['*.jar'], dir: 'libs')
provided 'javax.annotation:javax.annotation-api:1.2'
//provided 'javax.annotation:javax.annotation-api:1.2'
compile('io.netty:netty-all:4.0.28.Final') {
exclude group: 'commons-logging', module: 'commons-logging'

View File

@ -1,7 +1,5 @@
package org.ethereum.datasource;
import android.content.Context;
import org.ethereum.config.SystemProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -27,7 +25,6 @@ public class InMemoryDbDataSource implements KeyValueDataSource {
String name;
HashMap<ByteBuffer, byte[]> db;
private Context context;
public InMemoryDbDataSource() {
}
@ -36,10 +33,6 @@ public class InMemoryDbDataSource implements KeyValueDataSource {
this.name = name;
}
public void setContext(Context context) {
this.context = context;
}
@Override
public void init() {

View File

@ -21,8 +21,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
//import org.apache.commons.codec.binary.Base64;
import android.util.Base64;
import org.apache.commons.codec.binary.Base64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -106,8 +105,7 @@ public class JSONReader {
testSuiteObj = (JSONObject) parser.parse(blobresult);
String blob = (String) testSuiteObj.get("content");
//byte[] valueDecoded= Base64.decodeBase64(blob.getBytes() );
byte[] valueDecoded= Base64.decode(blob.getBytes(), Base64.DEFAULT);
byte[] valueDecoded= Base64.decodeBase64(blob.getBytes() );
//System.out.println("Decoded value is " + new String(valueDecoded));
return new String(valueDecoded);
}

View File

@ -1 +1,2 @@
include ':app', ':ethereumj-core'
include ':app', ':ethereumj-core-android'
include ':ethereumj-core'