Skip to content

Instantly share code, notes, and snippets.

public void displayShelf(List<String> images, RecyclerView items) {
//
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
itemWidth = getResources().getDimension(R.dimen.item_width);
padding = (size.x - itemWidth) / 2;
firstItemWidth = getResources().getDimension(R.dimen.padding_item_width);
allPixels = 0;
private void connect() {
MqttConnectOptions connectOptions = new MqttConnectOptions();
connectOptions.setAutomaticReconnect(true);
client = new MqttAndroidClient(this, serverURI, clientId);
try {
client.connect(connectOptions, new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken asyncActionToken) {
subscribe();
private void subscribe() {
String subscribeTopic = "inbox";
try {
client.subscribe(subscribeTopic, 0, new IMqttMessageListener() {
@Override
public void messageArrived(final String topic, final MqttMessage message) throws Exception {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, message.toString(), Toast.LENGTH_SHORT).show();
private void publishMessage(String message) {
String publishTopic = "outbox";
MqttMessage msg = new MqttMessage();
msg.setPayload(message.getBytes());
try {
client.publish(publishTopic, msg);
} catch (MqttException e) {
e.printStackTrace();
}
}
@beersheba
beersheba / login.xml
Created April 15, 2019 14:46
Login navigation graph
<?xml version="1.0" encoding="utf-8"?>
<navigation 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:id="@+id/login_nav"
app:startDestination="@id/loginHomeFragment">
<fragment
android:id="@+id/loginHomeFragment"
android:name="me.rankov.kaboom.login.LoginHomeFragment"
android:label="fragment_login_home"
import 'package:flutter/material.dart';
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
State<HomePage> createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {