Tôi quên tên cụ thể rồi - bóng đá nhà cái

Mục lục

Tự tạo Wallpaper METER bằng Processing-Android

Bước Một: Vẽ Nền và Tam Giác Tín Hiệu WIFI

Tham khảo: background() | triangle()

void setup() 
{
 fullScreen(P3D); // P2D cũng hoạt động tốt.
}
void draw() 
{
 background(12, 39, 43); // Màu nền
 beginShape(TRIANGLES);
 fill(0,94,83); // Màu nền tam giác WIFI
 vertex(width / 6 * 1, height / 5 * 1);
 vertex(width / 2, height / 5 * 3); [bóng đá nhà cái](/news/325e21dab024eed3/) 
 vertex(width *5 / 6, height / 5 * 1);
 endShape();
}

Kết quả:

Bước Hai: Vẽ Trường SSID của WIFI

Trước tiên, trong Processing - Android - Sketch Permissions hãy chọn android.permission.ACCESS_WIFI_STATE, nếu không ứng dụng sẽ bị đóng khi cố gắng truy cập thông tin WIFI. Để lấy Context, tham khảo processing-android/issues/227, ở đây chúng ta sử dụng surface.getComponent();

import android.net.wifi.*;
import android.content.*;
import android.app.*;
import processing.core.*;
import android.os.Bundle;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
String wifiName;
android.content.Context context;
void setup() 
{
 fullScreen(P3D);
}
void draw() 
{
 background(12, 39, 43);
 beginShape(TRIANGLES);
 fill(0,94,83);
 vertex(width / 6 * 1, height / 5 * 1);
 vertex(width / 2, height / 5 * 1 + width / 3 * 2);
 vertex(width *5 / 6, height / 5 * 1);
 endShape();
 
 textSize(width / 20); // Kích thước font SSID WIFI
 textAlign(CENTER, CENTER);
 text("WIFI : "+wifiName, width / 2, height / 5 * 1 + width / 3 * 2 + height / 20);
 fill(0, 102, 153);
}
public void onResume() {
 super.onResume(); 
 context = (Context) surface.getComponent();
 WifiManager wifiManager = (WifiManager) context.getSystemService (Context.WIFI_SERVICE);
 WifiInfo info = wifiManager.getConnectionInfo ();
 wifiName = info.getSSID(); // Lấy SSID
}
public void onPause() {
 super.onPause();
}

Bước Ba: Vẽ Độ Mạnh Tín Hiệu WIFI

Ở bước này, chúng ta cần điều chỉnh để lấy độ mạnh tín hiệu và SSID không còn được thực hiện trong onResume(). Lý do là onResume() thường chỉ kích hoạt khi chuyển từ nền sang màn hình chính, nhưng chúng ta cần đảm bảo rằng thông tin được làm mới liên tục ngay cả khi đang ở Launcher. Do đó, chúng ta thiết lập một Timer để lấy dữ liệu mỗi mười giây.

import android.net.wifi.*;
import android.content.*;
import android.app.*;
import processing.core.*;
import android.os.Bundle;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import java.util.*;
String wifiName;
int wifiLevel; // Từ 0 đến 10
android.content.Context context;
boolean canRefreshWifi;
float Point1X,Point2X,Point3X;
float Point1Y,Point2Y,Point3Y;
void setup() 
{
 fullScreen(P3D);
 
  Timer t = new Timer(); // Chạy mỗi 10 giây.
  t.scheduleAtFixedRate(new TimerTask() {
    @Override
    public void run() {
      if (canRefreshWifi)
      {
       context = (Context) surface.getComponent();
 WifiManager wifiManager = (WifiManager) context.getSystemService (Context.WIFI_SERVICE);
 WifiInfo info = wifiManager.getConnectionInfo ();
 wifiName = info.getSSID();
 wifiLevel = WifiManager.calculateSignalLevel(info.getRssi(), 11); // Độ mạnh tín hiệu
      }
    }
  
  },0,10000);
}
void draw() 
{
 background(12, 39, 43);
 beginShape(TRIANGLES); // Tam giác nền
 fill(0,94,83);
 vertex(Point1X, Point1Y);
 vertex(Point2X, Point2Y);
 vertex(Point3X, Point3Y);
 endShape();
 
 beginShape(TRIANGLES); // Tam giác trước cảnh
 fill(37,206,182);
 vertex(Point2X + (Point1X - Point2X) * wifiLevel / 10, Point2Y + (Point1Y - Point2Y) * wifiLevel / 10);
 vertex(Point2X, Point2Y);
 vertex(Point2X + (Point3X - Point2X) * wifiLevel / 10, Point2Y + (Point3Y - Point2Y) * wifiLevel / 10);
 endShape();
 
 textSize(width / 20);
 textAlign(CENTER, CENTER);
 text("WIFI : "+wifiName, width / 2, height / 5 * 1 + width / 3 * 2 + height / 20);
 fill(0, 102, 153);
}
public void onResume() {
 super.onResume(); 
 canRefreshWifi = true; // Quay lại màn hình chính, có thể tiếp tục làm mới thông tin WIFI.
 
 Point1X = width / 6;
 Point2X = width / 2;
 Point3X = width / 6 * 5;
 
 Point1Y = height / 5;
 Point2Y = height / 5 * 1 + width / 3 * 2;
 Point3Y = height / 5;
}
public void onPause() {
 super.onPause();
 canRefreshWifi = false;
}

Bước Tư: Thêm Hiệu Ứng Cán Cân Bằng

Thêm quyền truy cập vị trí địa lý, bao gồm hai quyền bắt đầu bằng ACCESS và chứa LOCATION. Tôi quên kèo bóng đá hôm nay tên cụ thể rồi. Đoạn mã dài hơn nên tôi đã đặt nó lên Gist. Phần cuối viết hơi rối, hiệu suất kém nhưng vẫn đủ dùng như một ví dụ minh họa. Như hình dưới đây.

Đến đây, chúng ta đã cơ bản hoàn thành một wallpaper động tương tự game ban ca doi thuong METER, có khả năng hiển thị SSID, mức độ mạnh yếu của tín hiệu và hiệu ứng cân bằng.