/* * Copyright 2015 Christian Basler * * 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. */ package ch.dissem.apps.abit import android.app.Activity import android.net.Uri import android.os.Bundle import android.support.v7.app.AppCompatActivity import android.util.Base64 import android.util.Base64.URL_SAFE import android.widget.Button import android.widget.EditText import android.widget.Switch import android.widget.TextView import ch.dissem.apps.abit.service.Singleton import ch.dissem.bitmessage.entity.BitmessageAddress import ch.dissem.bitmessage.entity.payload.V2Pubkey import ch.dissem.bitmessage.entity.payload.V3Pubkey import ch.dissem.bitmessage.entity.payload.V4Pubkey import org.slf4j.LoggerFactory import java.io.ByteArrayInputStream import java.util.regex.Pattern class CreateAddressActivity : AppCompatActivity() { private var pubkeyBytes: ByteArray? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val uri = intent.data if (uri != null) setContentView(R.layout.activity_open_bitmessage_link) else setContentView(R.layout.activity_create_bitmessage_address) val address = findViewById(R.id.address) val label = findViewById(R.id.label) val subscribe = findViewById(R.id.subscribe) if (uri != null) { val addressText = getAddress(uri) val parameters = getParameters(uri) for (parameter in parameters) { val matcher = KEY_VALUE_PATTERN.matcher(parameter) if (matcher.find()) { val key = matcher.group(1).toLowerCase() val value = matcher.group(2) when (key) { "label" -> label.setText(value.trim { it <= ' ' }) "action" -> subscribe.isChecked = value.trim { it <= ' ' }.equals("subscribe", ignoreCase = true) "pubkey" -> pubkeyBytes = Base64.decode(value, URL_SAFE) else -> LOG.debug("Unknown attribute: $key=$value") } } } address.text = addressText } val cancel = findViewById