Sign up
Login
New
Trending
Archive
English
English
Sign up
Login
New Paste
Add Image
package com.example.lab6_2024_2025_eng import android.content.Intent import android.os.Bundle import android.webkit.JavascriptInterface import android.webkit.WebView import androidx.appcompat.app.AppCompatActivity // -------- JS interface (must be a separate class) ---------- class GiftsJS(private val activity: Gifts) { @JavascriptInterface fun addGift(name: String) { activity.giftsList.add(name) } @JavascriptInterface fun generateCard() { val intent = Intent(activity, Card::class.java) // join all gifts into one long string intent.putExtra("gifts", activity.giftsList.joinToString("\n")) activity.startActivity(intent) } } // -------- Gifts Activity ----------------------------------- class Gifts : AppCompatActivity() { val giftsList = ArrayList<String>() // new list every app launch override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val page = WebView(this) page.settings.javaScriptEnabled = true page.addJavascriptInterface(GiftsJS(this), "backend") page.loadUrl("file:///android_asset/Gifts.html") setContentView(page) } } <html> <body> <h2>Gift List</h2> <input id="gift" type="text" placeholder="Enter gift"/><br><br> <button onclick="addGift()">Add</button> <button onclick="generate()">Generate postcard</button> <script type="text/javascript"> function addGift() { const name = document.getElementById("gift").value; backend.addGift(name); document.getElementById("gift").value = ""; } function generate() { backend.generateCard(); } </script> </body> </html> package com.example.lab6_2024_2025_eng import android.os.Bundle import android.webkit.JavascriptInterface import android.webkit.WebView import androidx.appcompat.app.AppCompatActivity class CardJS(private val gifts: String) { @JavascriptInterface fun getGifts(): String = gifts } class Card : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val gifts = intent.getStringExtra("gifts") ?: "" val page = WebView(this) page.settings.javaScriptEnabled = true page.addJavascriptInterface(CardJS(gifts), "backend") page.loadUrl("file:///android_asset/Card.html") setContentView(page) } } <html> <body style=" background-image: url('card.jpg'); background-size: cover; background-repeat: no-repeat; "> <h2>Your Wish List</h2> <div id="wishbox" style="width:90%; height:70%; overflow:auto; background:white; opacity:0.8;"> </div> <script> window.onload = function() { document.getElementById("wishbox").innerText = backend.getGifts(); } </script> </body> </html>
Settings
Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English