Today, I'm recording the reflection effect of a TextView. The goal is to display a string of text and then show its reflection directly below it. Here's the visual result:

Android realizes TextView text reflection effect

The key method used here is getDrawingCache() from the View class, which captures the current drawing of the view into a bitmap and allows us to draw it again. This is essential for creating the reflection effect.

Instead of getting stuck in theory, I wanted to build a real-time clock with a reflection effect. First, I created a custom TextView that displays the current time and updates every second. This part is straightforward — we can use a Handler and a separate thread to update the time periodically.

To implement this, I extended the TextView class and added a background thread that runs continuously. Every second, it sends a message to the main thread to update the displayed time. Below is the code for the TimeView class:

Package com.alex.reflecttextview;

Import java.util.Calendar;

Import android.content.Context;

Import android.os.Handler;

Import android.os.Message;

Import android.text.format.DateFormat;

Import android.util.AttributeSet;

Import android.widget.TextView;

Public class TimeView extends TextView {

Private static final int MESSAGE_TIME = 1;

Public TimeView(Context context, AttributeSet attrs) {

Super(context, attrs);

New TimeThread().start();

}

Public class TimeThread extends Thread {

@Override

Public void run() {

Do {

Try {

Message msg = new Message();

msg.what = MESSAGE_TIME;

mHandler.sendMessage(msg);

Thread.sleep(1000);

} catch (InterruptedException e) {

e.printStackTrace();

}

} while (true);

}

}

Private Handler mHandler = new Handler() {

@Override

Public void handleMessage(Message msg) {

super.handleMessage(msg);

Switch (msg.what) {

Case MESSAGE_TIME:

setTime();

Break;

Default:

Break;

}

}

};

Public void setTime() {

Long sysTime = System.currentTimeMillis();

Calendar calendar = Calendar.getInstance();

calendar.setTimeInMillis(sysTime);

String sysTimeStr = DateFormat.format("hh:mm", sysTime).toString();

If(calendar.get(Calendar.AM_PM) == 0) {

sysTimeStr += " AM";

} else {

sysTimeStr += " PM";

}

setText(sysTimeStr.replace("1", "1"));

}

}

This class provides a simple but effective way to display the current time in a custom TextView. Now, the next step is to add the reflection effect using the getDrawingCache() method. We can take the bitmap of the original text and draw it again, flipped vertically to create the illusion of a mirror image below the original text.

By combining this technique with the time-updating functionality, we can create a visually appealing and interactive UI element that reflects the current time in a unique way. This approach not only demonstrates Android's drawing capabilities but also shows how to combine multiple features to build more complex and engaging user interfaces.

On Grid Solar Energy System

On grid solar energy system refers to a type of Solar Energy System that is connected to the electrical grid, allowing the excess electricity generated by the solar panels to be sent back into the grid for distribution to other users. This solar power system can operate in two modes: when there is sufficient sunlight to power the household's needs, the system supplies power directly to the home; when there isn't enough sunlight, the grid fills the gap by providing power.


Features

1. Energy Savings: By generating your own electricity, you can significantly reduce your reliance on traditional utility providers, leading to substantial savings on electricity bills.
2. Stability: On grid systems are designed to be highly reliable, ensuring consistent power supply to the home. They are also equipped with advanced safety features to prevent power surges and ensure safe operation.
3. Grid Backup: In the event of a power outage, grid-tied systems often have the capability to switch to battery backup, providing temporary power to critical loads within the home.
4. Enhanced Property Value: Installing a solar energy system can increase the value of your property, making it a smart investment.

The setup typically involves solar panels installed on rooftops or in open spaces, an inverter to convert the direct current (DC) from the solar panels into alternating current (AC), which is compatible with the grid, and a meter that tracks the energy produced and consumed. The system is monitored through a control panel or app, providing real-time data on energy generation and consumption.

On Grid Solar,On The Grid Solar Power System,On Grid Solar System,Grid-Connected Solar Systems

Ningbo Taiye Technology Co., Ltd. , https://www.tysolarpower.com