Initial commit
A.k.a. "I should have done this some time ago"
This commit is contained in:
commit
89a5ada48a
191
.gitignore
vendored
Normal file
191
.gitignore
vendored
Normal file
@ -0,0 +1,191 @@
|
||||
# Created by https://www.gitignore.io
|
||||
|
||||
### Android ###
|
||||
# Built application files
|
||||
*.apk
|
||||
*.ap_
|
||||
|
||||
# Files for the Dalvik VM
|
||||
*.dex
|
||||
|
||||
# Java class files
|
||||
*.class
|
||||
|
||||
# Generated files
|
||||
bin/
|
||||
gen/
|
||||
|
||||
# Gradle files
|
||||
.gradle/
|
||||
build/
|
||||
/*/build/
|
||||
|
||||
# Local configuration file (sdk path, etc)
|
||||
local.properties
|
||||
|
||||
# Proguard folder generated by Eclipse
|
||||
proguard/
|
||||
|
||||
# Log Files
|
||||
*.log
|
||||
|
||||
### Android Patch ###
|
||||
gen-external-apklibs
|
||||
|
||||
|
||||
### Gradle ###
|
||||
.gradle
|
||||
build/
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
gradle-app.setting
|
||||
|
||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||
!gradle-wrapper.jar
|
||||
|
||||
|
||||
### Intellij ###
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
|
||||
|
||||
*.iml
|
||||
|
||||
## Directory-based project format:
|
||||
.idea/
|
||||
# if you remove the above rule, at least ignore the following:
|
||||
|
||||
# User-specific stuff:
|
||||
# .idea/workspace.xml
|
||||
# .idea/tasks.xml
|
||||
# .idea/dictionaries
|
||||
|
||||
# Sensitive or high-churn files:
|
||||
# .idea/dataSources.ids
|
||||
# .idea/dataSources.xml
|
||||
# .idea/sqlDataSources.xml
|
||||
# .idea/dynamic.xml
|
||||
# .idea/uiDesigner.xml
|
||||
|
||||
# Gradle:
|
||||
# .idea/gradle.xml
|
||||
# .idea/libraries
|
||||
|
||||
# Mongo Explorer plugin:
|
||||
# .idea/mongoSettings.xml
|
||||
|
||||
## File-based project format:
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
/out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
|
||||
|
||||
### Eclipse ###
|
||||
*.pydevproject
|
||||
.metadata
|
||||
.gradle
|
||||
bin/
|
||||
tmp/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
local.properties
|
||||
.settings/
|
||||
.loadpath
|
||||
|
||||
# Eclipse Core
|
||||
.project
|
||||
|
||||
# External tool builders
|
||||
.externalToolBuilders/
|
||||
|
||||
# Locally stored "Eclipse launch configurations"
|
||||
*.launch
|
||||
|
||||
# CDT-specific
|
||||
.cproject
|
||||
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
|
||||
# PDT-specific
|
||||
.buildpath
|
||||
|
||||
# sbteclipse plugin
|
||||
.target
|
||||
|
||||
# TeXlipse plugin
|
||||
.texlipse
|
||||
|
||||
|
||||
### Linux ###
|
||||
*~
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
|
||||
### OSX ###
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
|
||||
### Windows ###
|
||||
# Windows image file caches
|
||||
Thumbs.db
|
||||
ehthumbs.db
|
||||
|
||||
# Folder config file
|
||||
Desktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
1
app/.gitignore
vendored
Normal file
1
app/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/build
|
51
app/build.gradle
Normal file
51
app/build.gradle
Normal file
@ -0,0 +1,51 @@
|
||||
apply plugin: 'idea'
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
compileSdkVersion 22
|
||||
buildToolsVersion "21.1.2"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "ch.dissem.apps.abit"
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 22
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile 'com.android.support:appcompat-v7:22.2.1'
|
||||
compile 'com.android.support:support-v4:22.2.1'
|
||||
compile 'com.android.support:design:22.2.1'
|
||||
|
||||
compile 'ch.dissem.jabit:jabit-domain:0.2.1-SNAPSHOT'
|
||||
compile 'ch.dissem.jabit:jabit-networking:0.2.1-SNAPSHOT'
|
||||
compile 'ch.dissem.jabit:jabit-repositories:0.2.1-SNAPSHOT'
|
||||
compile 'ch.dissem.jabit:jabit-security-spongy:0.2.1-SNAPSHOT'
|
||||
|
||||
compile 'org.sqldroid:sqldroid:1.0.3'
|
||||
compile 'org.slf4j:slf4j-android:1.7.12'
|
||||
|
||||
compile('com.mikepenz:materialdrawer:3.1.0@aar') {
|
||||
transitive = true
|
||||
}
|
||||
}
|
||||
|
||||
idea.module {
|
||||
downloadJavadoc = true
|
||||
downloadSources = true
|
||||
}
|
||||
|
||||
android {
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
}
|
17
app/proguard-rules.pro
vendored
Normal file
17
app/proguard-rules.pro
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in /Users/chris/Library/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 *;
|
||||
#}
|
@ -0,0 +1,13 @@
|
||||
package ch.dissem.apps.abit;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
51
app/src/main/AndroidManifest.xml
Normal file
51
app/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="ch.dissem.apps.abit">
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".MessageListActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".MessageDetailActivity"
|
||||
android:label="@string/title_message_detail"
|
||||
android:parentActivityName=".MessageListActivity"
|
||||
tools:ignore="UnusedAttribute">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".MessageListActivity"/>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".SettingsActivity"
|
||||
android:label="@string/settings"
|
||||
android:parentActivityName=".MessageListActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MANAGE_NETWORK_USAGE"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".service.BitmessageService"
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
android:permission="">
|
||||
</service>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,8 @@
|
||||
CREATE TABLE Inventory (
|
||||
hash BINARY(32) NOT NULL PRIMARY KEY,
|
||||
stream INTEGER NOT NULL,
|
||||
expires INTEGER NOT NULL,
|
||||
data BLOB NOT NULL,
|
||||
type INTEGER NOT NULL,
|
||||
version INTEGER NOT NULL
|
||||
);
|
@ -0,0 +1,8 @@
|
||||
CREATE TABLE Address (
|
||||
address VARCHAR(40) NOT NULL PRIMARY KEY,
|
||||
version INTEGER NOT NULL,
|
||||
alias VARCHAR(255),
|
||||
public_key BLOB,
|
||||
private_key BLOB,
|
||||
subscribed BIT DEFAULT '0'
|
||||
);
|
@ -0,0 +1,40 @@
|
||||
CREATE TABLE Message (
|
||||
id INTEGER PRIMARY KEY,
|
||||
iv BINARY(32) UNIQUE,
|
||||
type VARCHAR(20) NOT NULL,
|
||||
sender VARCHAR(40) NOT NULL,
|
||||
recipient VARCHAR(40),
|
||||
data BLOB NOT NULL,
|
||||
sent INTEGER,
|
||||
received INTEGER,
|
||||
status VARCHAR(20) NOT NULL,
|
||||
|
||||
FOREIGN KEY (sender) REFERENCES Address (address),
|
||||
FOREIGN KEY (recipient) REFERENCES Address (address)
|
||||
);
|
||||
|
||||
CREATE TABLE Label (
|
||||
id INTEGER PRIMARY KEY,
|
||||
label VARCHAR(255) NOT NULL,
|
||||
type VARCHAR(20),
|
||||
color INT NOT NULL DEFAULT 4278190080, -- FF000000
|
||||
ord INTEGER,
|
||||
|
||||
CONSTRAINT UC_label UNIQUE (label),
|
||||
CONSTRAINT UC_order UNIQUE (ord)
|
||||
);
|
||||
|
||||
CREATE TABLE Message_Label (
|
||||
message_id INTEGER NOT NULL,
|
||||
label_id INTEGER NOT NULL,
|
||||
|
||||
PRIMARY KEY (message_id, label_id),
|
||||
FOREIGN KEY (message_id) REFERENCES Message (id),
|
||||
FOREIGN KEY (label_id) REFERENCES Label (id)
|
||||
);
|
||||
|
||||
INSERT INTO Label(label, type, color, ord) VALUES ('Inbox', 'INBOX', 4278190335, 0);
|
||||
INSERT INTO Label(label, type, color, ord) VALUES ('Drafts', 'DRAFT', 4294940928, 10);
|
||||
INSERT INTO Label(label, type, color, ord) VALUES ('Sent', 'SENT', 4294967040, 20);
|
||||
INSERT INTO Label(label, type, ord) VALUES ('Unread', 'UNREAD', 90);
|
||||
INSERT INTO Label(label, type, ord) VALUES ('Trash', 'TRASH', 100);
|
@ -0,0 +1,68 @@
|
||||
package ch.dissem.apps.abit;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v4.app.NavUtils;
|
||||
import android.view.MenuItem;
|
||||
|
||||
|
||||
/**
|
||||
* An activity representing a single Message detail screen. This
|
||||
* activity is only used on handset devices. On tablet-size devices,
|
||||
* item details are presented side-by-side with a list of items
|
||||
* in a {@link MessageListActivity}.
|
||||
* <p/>
|
||||
* This activity is mostly just a 'shell' activity containing nothing
|
||||
* more than a {@link MessageDetailFragment}.
|
||||
*/
|
||||
public class MessageDetailActivity extends ActionBarActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_message_detail);
|
||||
|
||||
// Show the Up button in the action bar.
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
// savedInstanceState is non-null when there is fragment state
|
||||
// saved from previous configurations of this activity
|
||||
// (e.g. when rotating the screen from portrait to landscape).
|
||||
// In this case, the fragment will automatically be re-added
|
||||
// to its container so we don't need to manually add it.
|
||||
// For more information, see the Fragments API guide at:
|
||||
//
|
||||
// http://developer.android.com/guide/components/fragments.html
|
||||
//
|
||||
if (savedInstanceState == null) {
|
||||
// Create the detail fragment and add it to the activity
|
||||
// using a fragment transaction.
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putString(MessageDetailFragment.ARG_ITEM,
|
||||
getIntent().getStringExtra(MessageDetailFragment.ARG_ITEM));
|
||||
MessageDetailFragment fragment = new MessageDetailFragment();
|
||||
fragment.setArguments(arguments);
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.message_detail_container, fragment)
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
if (id == android.R.id.home) {
|
||||
// This ID represents the Home or Up button. In the case of this
|
||||
// activity, the Up button is shown. Use NavUtils to allow users
|
||||
// to navigate up one level in the application structure. For
|
||||
// more details, see the Navigation pattern on Android Design:
|
||||
//
|
||||
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
|
||||
//
|
||||
NavUtils.navigateUpTo(this, new Intent(this, MessageListActivity.class));
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
package ch.dissem.apps.abit;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import ch.dissem.bitmessage.entity.Plaintext;
|
||||
|
||||
|
||||
/**
|
||||
* A fragment representing a single Message detail screen.
|
||||
* This fragment is either contained in a {@link MessageListActivity}
|
||||
* in two-pane mode (on tablets) or a {@link MessageDetailActivity}
|
||||
* on handsets.
|
||||
*/
|
||||
public class MessageDetailFragment extends Fragment {
|
||||
/**
|
||||
* The fragment argument representing the item ID that this fragment
|
||||
* represents.
|
||||
*/
|
||||
public static final String ARG_ITEM = "item";
|
||||
|
||||
/**
|
||||
* The dummy content this fragment is presenting.
|
||||
*/
|
||||
private Plaintext item;
|
||||
|
||||
/**
|
||||
* Mandatory empty constructor for the fragment manager to instantiate the
|
||||
* fragment (e.g. upon screen orientation changes).
|
||||
*/
|
||||
public MessageDetailFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
if (getArguments().containsKey(ARG_ITEM)) {
|
||||
// Load the dummy content specified by the fragment
|
||||
// arguments. In a real-world scenario, use a Loader
|
||||
// to load content from a content provider.
|
||||
item = (Plaintext) getArguments().getSerializable(ARG_ITEM);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_message_detail, container, false);
|
||||
|
||||
// Show the dummy content as text in a TextView.
|
||||
if (item != null) {
|
||||
((TextView) rootView.findViewById(R.id.message_detail)).setText(item.getText());
|
||||
}
|
||||
|
||||
return rootView;
|
||||
}
|
||||
}
|
215
app/src/main/java/ch/dissem/apps/abit/MessageListActivity.java
Normal file
215
app/src/main/java/ch/dissem/apps/abit/MessageListActivity.java
Normal file
@ -0,0 +1,215 @@
|
||||
package ch.dissem.apps.abit;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import ch.dissem.apps.abit.service.Singleton;
|
||||
import ch.dissem.bitmessage.BitmessageContext;
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
import ch.dissem.bitmessage.entity.Plaintext;
|
||||
import ch.dissem.bitmessage.entity.valueobject.Label;
|
||||
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
|
||||
import com.mikepenz.iconics.IconicsDrawable;
|
||||
import com.mikepenz.materialdrawer.Drawer;
|
||||
import com.mikepenz.materialdrawer.DrawerBuilder;
|
||||
import com.mikepenz.materialdrawer.accountswitcher.AccountHeader;
|
||||
import com.mikepenz.materialdrawer.accountswitcher.AccountHeaderBuilder;
|
||||
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IProfile;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.Nameable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
/**
|
||||
* An activity representing a list of Messages. This activity
|
||||
* has different presentations for handset and tablet-size devices. On
|
||||
* handsets, the activity presents a list of items, which when touched,
|
||||
* lead to a {@link MessageDetailActivity} representing
|
||||
* item details. On tablets, the activity presents the list of items and
|
||||
* item details side-by-side using two vertical panes.
|
||||
* <p>
|
||||
* The activity makes heavy use of fragments. The list of items is a
|
||||
* {@link MessageListFragment} and the item details
|
||||
* (if present) is a {@link MessageDetailFragment}.
|
||||
* </p><p>
|
||||
* This activity also implements the required
|
||||
* {@link MessageListFragment.Callbacks} interface
|
||||
* to listen for item selections.
|
||||
* </p>
|
||||
*/
|
||||
public class MessageListActivity extends AppCompatActivity
|
||||
implements MessageListFragment.Callbacks {
|
||||
private static final int ADD_IDENTITY = 1;
|
||||
|
||||
/**
|
||||
* Whether or not the activity is in two-pane mode, i.e. running on a tablet
|
||||
* device.
|
||||
*/
|
||||
private boolean twoPane;
|
||||
|
||||
private AccountHeader accountHeader;
|
||||
private BitmessageContext bmc;
|
||||
private Label selectedLabel;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
bmc = Singleton.getBitmessageContext(this);
|
||||
selectedLabel = bmc.messages().getLabels().get(0);
|
||||
|
||||
setContentView(R.layout.activity_message_list);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
if (findViewById(R.id.message_detail_container) != null) {
|
||||
// The detail container view will be present only in the
|
||||
// large-screen layouts (res/values-large and
|
||||
// res/values-sw600dp). If this view is present, then the
|
||||
// activity should be in two-pane mode.
|
||||
twoPane = true;
|
||||
|
||||
// In two-pane mode, list items should be given the
|
||||
// 'activated' state when touched.
|
||||
((MessageListFragment) getSupportFragmentManager()
|
||||
.findFragmentById(R.id.message_list))
|
||||
.setActivateOnItemClick(true);
|
||||
}
|
||||
|
||||
createDrawer(toolbar);
|
||||
|
||||
// TODO: If exposing deep links into your app, handle intents here.
|
||||
}
|
||||
|
||||
private void createDrawer(Toolbar toolbar) {
|
||||
final ArrayList<IProfile> profiles = new ArrayList<>();
|
||||
for (BitmessageAddress identity : bmc.addresses().getIdentities()) {
|
||||
profiles.add(new ProfileDrawerItem()
|
||||
.withName(identity.toString())
|
||||
.withEmail(identity.getAddress())
|
||||
.withTag(identity)
|
||||
);
|
||||
}
|
||||
profiles.add(new ProfileSettingDrawerItem()
|
||||
.withName("Add Identity")
|
||||
.withDescription("Create new identity")
|
||||
.withIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_add)
|
||||
.actionBar()
|
||||
.paddingDp(5)
|
||||
.colorRes(R.color.icons))
|
||||
.withIdentifier(ADD_IDENTITY)
|
||||
);
|
||||
profiles.add(new ProfileSettingDrawerItem()
|
||||
.withName("Manage Account")
|
||||
.withIcon(GoogleMaterial.Icon.gmd_settings)
|
||||
);
|
||||
// Create the AccountHeader
|
||||
accountHeader = new AccountHeaderBuilder()
|
||||
.withActivity(this)
|
||||
.withHeaderBackground(R.drawable.header)
|
||||
.withProfiles(profiles)
|
||||
.withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
|
||||
@Override
|
||||
public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
|
||||
if (profile.getIdentifier() == ADD_IDENTITY) {
|
||||
BitmessageAddress identity = bmc.createIdentity(false);
|
||||
IProfile newProfile = new ProfileDrawerItem()
|
||||
.withName(identity.toString())
|
||||
.withEmail(identity.getAddress())
|
||||
.withTag(identity);
|
||||
if (accountHeader.getProfiles() != null) {
|
||||
//we know that there are 2 setting elements. set the new profile above them ;)
|
||||
accountHeader.addProfile(newProfile, accountHeader.getProfiles().size() - 2);
|
||||
} else {
|
||||
accountHeader.addProfiles(newProfile);
|
||||
}
|
||||
}
|
||||
// false if it should close the drawer
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
ArrayList<IDrawerItem> drawerItems = new ArrayList<>();
|
||||
for (Label label : bmc.messages().getLabels()) {
|
||||
drawerItems.add(new PrimaryDrawerItem().withName(label.toString()).withTag(label));
|
||||
}
|
||||
|
||||
new DrawerBuilder()
|
||||
.withActivity(this)
|
||||
.withToolbar(toolbar)
|
||||
.withAccountHeader(accountHeader)
|
||||
.withDrawerItems(drawerItems)
|
||||
.addStickyDrawerItems(
|
||||
new SecondaryDrawerItem()
|
||||
.withName(R.string.settings)
|
||||
.withIcon(GoogleMaterial.Icon.gmd_settings)
|
||||
)
|
||||
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
|
||||
@Override
|
||||
public boolean onItemClick(AdapterView<?> adapterView, View view, int i, long l, IDrawerItem item) {
|
||||
if (item.getTag() instanceof Label) {
|
||||
selectedLabel = (Label) item.getTag();
|
||||
} else if (item instanceof Nameable<?>) {
|
||||
Nameable<?> ni = (Nameable<?>) item;
|
||||
switch (ni.getNameRes()) {
|
||||
case R.string.settings:
|
||||
startActivity(new Intent(MessageListActivity.this, SettingsActivity.class));
|
||||
break;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
boolean running = bmc.isRunning();
|
||||
menu.findItem(R.id.sync_enabled).setVisible(running);
|
||||
menu.findItem(R.id.sync_disabled).setVisible(!running);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback method from {@link MessageListFragment.Callbacks}
|
||||
* indicating that the item with the given ID was selected.
|
||||
*/
|
||||
@Override
|
||||
public void onItemSelected(Plaintext plaintext) {
|
||||
if (twoPane) {
|
||||
// In two-pane mode, show the detail view in this activity by
|
||||
// adding or replacing the detail fragment using a
|
||||
// fragment transaction.
|
||||
Bundle arguments = new Bundle();
|
||||
arguments.putSerializable(MessageDetailFragment.ARG_ITEM, plaintext);
|
||||
MessageDetailFragment fragment = new MessageDetailFragment();
|
||||
fragment.setArguments(arguments);
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.message_detail_container, fragment)
|
||||
.commit();
|
||||
|
||||
} else {
|
||||
// In single-pane mode, simply start the detail activity
|
||||
// for the selected item ID.
|
||||
Intent detailIntent = new Intent(this, MessageDetailActivity.class);
|
||||
detailIntent.putExtra(MessageDetailFragment.ARG_ITEM, plaintext);
|
||||
startActivity(detailIntent);
|
||||
}
|
||||
}
|
||||
|
||||
public Label getSelectedLabel() {
|
||||
return selectedLabel;
|
||||
}
|
||||
}
|
177
app/src/main/java/ch/dissem/apps/abit/MessageListFragment.java
Normal file
177
app/src/main/java/ch/dissem/apps/abit/MessageListFragment.java
Normal file
@ -0,0 +1,177 @@
|
||||
package ch.dissem.apps.abit;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import ch.dissem.apps.abit.service.Singleton;
|
||||
import ch.dissem.bitmessage.BitmessageContext;
|
||||
import ch.dissem.bitmessage.entity.Plaintext;
|
||||
|
||||
/**
|
||||
* A list fragment representing a list of Messages. This fragment
|
||||
* also supports tablet devices by allowing list items to be given an
|
||||
* 'activated' state upon selection. This helps indicate which item is
|
||||
* currently being viewed in a {@link MessageDetailFragment}.
|
||||
* <p/>
|
||||
* Activities containing this fragment MUST implement the {@link Callbacks}
|
||||
* interface.
|
||||
*/
|
||||
public class MessageListFragment extends ListFragment {
|
||||
|
||||
/**
|
||||
* The serialization (saved instance state) Bundle key representing the
|
||||
* activated item position. Only used on tablets.
|
||||
*/
|
||||
private static final String STATE_ACTIVATED_POSITION = "activated_position";
|
||||
|
||||
/**
|
||||
* The fragment's current callback object, which is notified of list item
|
||||
* clicks.
|
||||
*/
|
||||
private Callbacks mCallbacks = sDummyCallbacks;
|
||||
|
||||
/**
|
||||
* The current activated item position. Only used on tablets.
|
||||
*/
|
||||
private int mActivatedPosition = ListView.INVALID_POSITION;
|
||||
|
||||
private BitmessageContext bmc;
|
||||
|
||||
/**
|
||||
* A callback interface that all activities containing this fragment must
|
||||
* implement. This mechanism allows activities to be notified of item
|
||||
* selections.
|
||||
*/
|
||||
public interface Callbacks {
|
||||
/**
|
||||
* Callback for when an item has been selected.
|
||||
*/
|
||||
void onItemSelected(Plaintext plaintext);
|
||||
}
|
||||
|
||||
/**
|
||||
* A dummy implementation of the {@link Callbacks} interface that does
|
||||
* nothing. Used only when this fragment is not attached to an activity.
|
||||
*/
|
||||
private static Callbacks sDummyCallbacks = new Callbacks() {
|
||||
@Override
|
||||
public void onItemSelected(Plaintext plaintext) {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Mandatory empty constructor for the fragment manager to instantiate the
|
||||
* fragment (e.g. upon screen orientation changes).
|
||||
*/
|
||||
public MessageListFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
bmc = Singleton.getBitmessageContext(getActivity());
|
||||
|
||||
// TODO: replace with a real list adapter.
|
||||
setListAdapter(new ArrayAdapter<>(
|
||||
getActivity(),
|
||||
android.R.layout.simple_list_item_activated_1,
|
||||
android.R.id.text1,
|
||||
bmc.messages().findMessages(((MessageListActivity) getActivity()).getSelectedLabel())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_message_list, container, false);
|
||||
|
||||
// Show the dummy content as text in a TextView.
|
||||
FloatingActionButton fab = (FloatingActionButton) rootView.findViewById(R.id.fab_compose_message);
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Toast.makeText(MessageListFragment.this.getActivity(), "TODO", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
// Restore the previously serialized activated item position.
|
||||
if (savedInstanceState != null
|
||||
&& savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) {
|
||||
setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
||||
// Activities containing this fragment must implement its callbacks.
|
||||
if (!(activity instanceof Callbacks)) {
|
||||
throw new IllegalStateException("Activity must implement fragment's callbacks.");
|
||||
}
|
||||
|
||||
mCallbacks = (Callbacks) activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
|
||||
// Reset the active callbacks interface to the dummy implementation.
|
||||
mCallbacks = sDummyCallbacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListItemClick(ListView listView, View view, int position, long id) {
|
||||
super.onListItemClick(listView, view, position, id);
|
||||
|
||||
// Notify the active callbacks interface (the activity, if the
|
||||
// fragment is attached to one) that an item has been selected.
|
||||
mCallbacks.onItemSelected((Plaintext) listView.getItemAtPosition(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
if (mActivatedPosition != ListView.INVALID_POSITION) {
|
||||
// Serialize and persist the activated item position.
|
||||
outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns on activate-on-click mode. When this mode is on, list items will be
|
||||
* given the 'activated' state when touched.
|
||||
*/
|
||||
public void setActivateOnItemClick(boolean activateOnItemClick) {
|
||||
// When setting CHOICE_MODE_SINGLE, ListView will automatically
|
||||
// give items the 'activated' state when touched.
|
||||
getListView().setChoiceMode(activateOnItemClick
|
||||
? ListView.CHOICE_MODE_SINGLE
|
||||
: ListView.CHOICE_MODE_NONE);
|
||||
}
|
||||
|
||||
private void setActivatedPosition(int position) {
|
||||
if (position == ListView.INVALID_POSITION) {
|
||||
getListView().setItemChecked(mActivatedPosition, false);
|
||||
} else {
|
||||
getListView().setItemChecked(position, true);
|
||||
}
|
||||
|
||||
mActivatedPosition = position;
|
||||
}
|
||||
}
|
37
app/src/main/java/ch/dissem/apps/abit/SQLiteConfig.java
Normal file
37
app/src/main/java/ch/dissem/apps/abit/SQLiteConfig.java
Normal file
@ -0,0 +1,37 @@
|
||||
package ch.dissem.apps.abit;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Environment;
|
||||
import ch.dissem.bitmessage.repository.JdbcConfig;
|
||||
import org.flywaydb.core.api.android.ContextHolder;
|
||||
import org.sqldroid.SQLDroidDriver;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Created by chris on 14.07.15.
|
||||
*/
|
||||
public class SQLiteConfig extends JdbcConfig {
|
||||
|
||||
public SQLiteConfig(Context ctx) {
|
||||
super(getDbUrl(ctx), "", "");
|
||||
}
|
||||
|
||||
private static String getDbUrl(Context ctx) {
|
||||
SQLiteDatabase db = ctx.openOrCreateDatabase(Environment.getExternalStorageDirectory()
|
||||
+ "/jabit.db", Context.MODE_PRIVATE, null);
|
||||
ContextHolder.setContext(ctx);
|
||||
return "jdbc:sqlite:" + db.getPath() + "?timeout=5";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
Properties removeLocale = new Properties();
|
||||
removeLocale.put(SQLDroidDriver.ADDITONAL_DATABASE_FLAGS, android.database.sqlite.SQLiteDatabase.NO_LOCALIZED_COLLATORS);
|
||||
return DriverManager.getConnection(dbUrl, removeLocale);
|
||||
}
|
||||
}
|
27
app/src/main/java/ch/dissem/apps/abit/SettingsActivity.java
Normal file
27
app/src/main/java/ch/dissem/apps/abit/SettingsActivity.java
Normal file
@ -0,0 +1,27 @@
|
||||
package ch.dissem.apps.abit;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
|
||||
/**
|
||||
* Created by chris on 14.07.15.
|
||||
*/
|
||||
public class SettingsActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.toolbar_layout);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setHomeButtonEnabled(false);
|
||||
|
||||
// Display the fragment as the main content.
|
||||
getFragmentManager().beginTransaction()
|
||||
.replace(R.id.content, new SettingsFragment())
|
||||
.commit();
|
||||
}
|
||||
}
|
18
app/src/main/java/ch/dissem/apps/abit/SettingsFragment.java
Normal file
18
app/src/main/java/ch/dissem/apps/abit/SettingsFragment.java
Normal file
@ -0,0 +1,18 @@
|
||||
package ch.dissem.apps.abit;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceFragment;
|
||||
|
||||
/**
|
||||
* Created by chris on 14.07.15.
|
||||
*/
|
||||
public class SettingsFragment extends PreferenceFragment {
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Load the preferences from an XML resource
|
||||
addPreferencesFromResource(R.xml.preferences);
|
||||
}
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
package ch.dissem.apps.abit.service;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Binder;
|
||||
import android.os.IBinder;
|
||||
import android.support.v7.app.NotificationCompat;
|
||||
import ch.dissem.apps.abit.R;
|
||||
import ch.dissem.bitmessage.BitmessageContext;
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
import ch.dissem.bitmessage.entity.Plaintext;
|
||||
import ch.dissem.bitmessage.entity.valueobject.Label;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BitmessageService extends Service {
|
||||
private static BitmessageContext ctx;
|
||||
private ServiceBinder binder = new ServiceBinder();
|
||||
private NotificationCompat.Builder ongoingNotificationBuilder = new NotificationCompat.Builder(this);
|
||||
private NotificationManager notifyManager;
|
||||
|
||||
public BitmessageService() {
|
||||
if (ctx == null) {
|
||||
ctx = Singleton.getBitmessageContext(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
ongoingNotificationBuilder.setOngoing(true);
|
||||
ongoingNotificationBuilder.setContentTitle(getString(R.string.bitmessage_active));
|
||||
ongoingNotificationBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
|
||||
// ongoingNotificationBuilder.setSmallIcon(R.drawable.ic_bitmessage);
|
||||
notifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
}
|
||||
|
||||
public void startService() {
|
||||
if (!ctx.isRunning()) {
|
||||
notifyManager.notify(0, ongoingNotificationBuilder.build());
|
||||
ctx.startup(new BitmessageContext.Listener() {
|
||||
@Override
|
||||
public void receive(Plaintext plaintext) {
|
||||
Notification notification = new NotificationCompat.Builder(BitmessageService.this)
|
||||
.setContentTitle(plaintext.getSubject())
|
||||
.setContentText(plaintext.getText())
|
||||
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
||||
.setPriority(plaintext.getType() == Plaintext.Type.BROADCAST
|
||||
? NotificationCompat.PRIORITY_DEFAULT
|
||||
: NotificationCompat.PRIORITY_HIGH)
|
||||
.build();
|
||||
notifyManager.notify(plaintext.getInventoryVector().hashCode(), notification);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void stopService() {
|
||||
ctx.shutdown();
|
||||
notifyManager.cancel(0);
|
||||
}
|
||||
|
||||
public List<BitmessageAddress> getIdentities() {
|
||||
return ctx.addresses().getIdentities();
|
||||
}
|
||||
|
||||
public List<BitmessageAddress> getContacts() {
|
||||
return ctx.addresses().getContacts();
|
||||
}
|
||||
|
||||
public List<Plaintext> getMessages(Label label) {
|
||||
return ctx.messages().findMessages(label);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return binder;
|
||||
}
|
||||
|
||||
public class ServiceBinder extends Binder {
|
||||
public BitmessageService getService() {
|
||||
return BitmessageService.this;
|
||||
}
|
||||
}
|
||||
|
||||
public enum NetworkChoice {
|
||||
/**
|
||||
* A full node, receiving and relaying objects all the time.
|
||||
*/
|
||||
FULL,
|
||||
/**
|
||||
* Connect to a trusted node from time to time to get all new objects and disconnect afterwards
|
||||
* (see {@link android.content.AbstractThreadedSyncAdapter})
|
||||
*/
|
||||
TRUSTED,
|
||||
/**
|
||||
* Offline
|
||||
*/
|
||||
NONE
|
||||
}
|
||||
}
|
34
app/src/main/java/ch/dissem/apps/abit/service/Singleton.java
Normal file
34
app/src/main/java/ch/dissem/apps/abit/service/Singleton.java
Normal file
@ -0,0 +1,34 @@
|
||||
package ch.dissem.apps.abit.service;
|
||||
|
||||
import android.content.Context;
|
||||
import ch.dissem.apps.abit.SQLiteConfig;
|
||||
import ch.dissem.bitmessage.BitmessageContext;
|
||||
import ch.dissem.bitmessage.networking.DefaultNetworkHandler;
|
||||
import ch.dissem.bitmessage.repository.*;
|
||||
import ch.dissem.bitmessage.security.sc.SpongySecurity;
|
||||
|
||||
/**
|
||||
* Created by chris on 16.07.15.
|
||||
*/
|
||||
public class Singleton {
|
||||
private static BitmessageContext bitmessageContext;
|
||||
|
||||
public static BitmessageContext getBitmessageContext(Context ctx) {
|
||||
if (bitmessageContext == null) {
|
||||
synchronized (Singleton.class) {
|
||||
if (bitmessageContext == null) {
|
||||
JdbcConfig config = new SQLiteConfig(ctx);
|
||||
bitmessageContext = new BitmessageContext.Builder()
|
||||
.security(new SpongySecurity())
|
||||
.nodeRegistry(new MemoryNodeRegistry())
|
||||
.inventory(new JdbcInventory(config))
|
||||
.addressRepo(new JdbcAddressRepository(config))
|
||||
.messageRepo(new JdbcMessageRepository(config))
|
||||
.networkHandler(new DefaultNetworkHandler())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
return bitmessageContext;
|
||||
}
|
||||
}
|
213
app/src/main/java/im/delight/android/identicons/Identicon.java
Normal file
213
app/src/main/java/im/delight/android/identicons/Identicon.java
Normal file
@ -0,0 +1,213 @@
|
||||
package im.delight.android.identicons;
|
||||
|
||||
/**
|
||||
* Copyright 2014 www.delight.im <info@delight.im>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
abstract public class Identicon extends View {
|
||||
|
||||
private static final String HASH_ALGORITHM = "SHA-256";
|
||||
private final int mRowCount;
|
||||
private final int mColumnCount;
|
||||
private final Paint mPaint;
|
||||
private volatile int mCellWidth;
|
||||
private volatile int mCellHeight;
|
||||
private volatile byte[] mHash;
|
||||
private volatile int[][] mColors;
|
||||
private volatile boolean mReady;
|
||||
|
||||
public Identicon(Context context) {
|
||||
super(context);
|
||||
|
||||
mRowCount = getRowCount();
|
||||
mColumnCount = getColumnCount();
|
||||
mPaint = new Paint();
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
public Identicon(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
mRowCount = getRowCount();
|
||||
mColumnCount = getColumnCount();
|
||||
mPaint = new Paint();
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
public Identicon(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
mRowCount = getRowCount();
|
||||
mColumnCount = getColumnCount();
|
||||
mPaint = new Paint();
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
protected void init() {
|
||||
mPaint.setStyle(Paint.Style.FILL);
|
||||
mPaint.setAntiAlias(true);
|
||||
mPaint.setDither(true);
|
||||
|
||||
setWillNotDraw(false);
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
}
|
||||
}
|
||||
|
||||
public void show(String input) {
|
||||
// if the input was null
|
||||
if (input == null) {
|
||||
// we can't create a hash value and have nothing to show (draw to the view)
|
||||
mHash = null;
|
||||
}
|
||||
// if the input was a proper string (non-null)
|
||||
else {
|
||||
// generate a hash from the string to get unique but deterministic byte values
|
||||
try {
|
||||
final MessageDigest digest = java.security.MessageDigest.getInstance(HASH_ALGORITHM);
|
||||
digest.update(input == null ? new byte[0] : input.getBytes());
|
||||
mHash = digest.digest();
|
||||
}
|
||||
catch (Exception e) {
|
||||
mHash = null;
|
||||
}
|
||||
}
|
||||
|
||||
// set up the cell colors according to the input that was provided via show(...)
|
||||
setupColors();
|
||||
|
||||
// this view may now be drawn (and thus must be re-drawn)
|
||||
mReady = true;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void show(int input) {
|
||||
show(String.valueOf(input));
|
||||
}
|
||||
|
||||
public void show(long input) {
|
||||
show(String.valueOf(input));
|
||||
}
|
||||
|
||||
public void show(float input) {
|
||||
show(String.valueOf(input));
|
||||
}
|
||||
|
||||
public void show(double input) {
|
||||
show(String.valueOf(input));
|
||||
}
|
||||
|
||||
public void show(byte input) {
|
||||
show(String.valueOf(input));
|
||||
}
|
||||
|
||||
public void show(char input) {
|
||||
show(String.valueOf(input));
|
||||
}
|
||||
|
||||
public void show(boolean input) {
|
||||
show(String.valueOf(input));
|
||||
}
|
||||
|
||||
public void show(Object input) {
|
||||
if (input == null) {
|
||||
mHash = null;
|
||||
}
|
||||
else {
|
||||
show(String.valueOf(input));
|
||||
}
|
||||
}
|
||||
|
||||
protected void setupColors() {
|
||||
mColors = new int[mRowCount][mColumnCount];
|
||||
int colorVisible = getIconColor();
|
||||
|
||||
for (int r = 0; r < mRowCount; r++) {
|
||||
for (int c = 0; c < mColumnCount; c++) {
|
||||
if (isCellVisible(r, c)) {
|
||||
mColors[r][c] = colorVisible;
|
||||
}
|
||||
else {
|
||||
mColors[r][c] = Color.TRANSPARENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected byte getByte(int index) {
|
||||
if (mHash == null) {
|
||||
return -128;
|
||||
}
|
||||
else {
|
||||
return mHash[index % mHash.length];
|
||||
}
|
||||
}
|
||||
|
||||
abstract protected int getRowCount();
|
||||
|
||||
abstract protected int getColumnCount();
|
||||
|
||||
abstract protected boolean isCellVisible(int row, int column);
|
||||
|
||||
abstract protected int getIconColor();
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
|
||||
mCellWidth = w / mColumnCount;
|
||||
mCellHeight = h / mRowCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
int size = Math.min(getMeasuredWidth(), getMeasuredHeight());
|
||||
setMeasuredDimension(size, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
if (mReady) {
|
||||
int x, y;
|
||||
for (int r = 0; r < mRowCount; r++) {
|
||||
for (int c = 0; c < mColumnCount; c++) {
|
||||
x = mCellWidth * c;
|
||||
y = mCellHeight * r;
|
||||
|
||||
mPaint.setColor(mColors[r][c]);
|
||||
|
||||
canvas.drawRect(x, y + mCellHeight, x + mCellWidth, y, mPaint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
BIN
app/src/main/res/drawable-hdpi/ic_action_notification_sync.png
Executable file
BIN
app/src/main/res/drawable-hdpi/ic_action_notification_sync.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 967 B |
BIN
app/src/main/res/drawable-hdpi/ic_action_notification_sync_disabled.png
Executable file
BIN
app/src/main/res/drawable-hdpi/ic_action_notification_sync_disabled.png
Executable file
Binary file not shown.
|