知识很基础……

前几天买了个单反,特别想拍B门长时间曝光的效果。后来想想不如自己写个APP,实现屏幕背景的随机颜色以及全屏显示文字。

先上图:

这两张图片的左侧都很亮,这是因为APP里面忘记把"状态栏"隐藏了。两张照片的快门都是30s,APP的基本功能就是设定好文字,点击屏幕就会显示一个字;再点击屏幕编程黑色;再次点击屏幕出现下一个字。我在屏幕全黑的时候移动手机,到合适位置点击屏幕,显示出下一个字。同时屏幕还能够按照设定的时间间隔,显示出随机的颜色。为了使显示的颜色更鲜艳,在RGB颜色合成的时候,RGB的随机值都是从80~255。

同时文字在显示的时候,角度从45°到135°随机出现,这要在拍照时手机正常摆放,也不至于太过呆板。

下面是APP截图:

运行时的截图:

程序代码如下:

package com.example.raw;

import java.util.Timer;
import java.util.TimerTask; import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.TextView; public class MainActivity extends Activity { public int redColor = 0;
public int blueColor = 0;
public int greenColor = 0; public int tvRedColor = 0;
public int tvBlueColor = 0;
public int tvGreenColor = 0; public int tvRotation = 0;
public int clickTimes = 0;
public int i = 0; public char[] text = null; public boolean enableView = false; private LinearLayout ll;
private TimerTask task;
private Button btnTimeInterval, btnSetText;
private TextView etTimeInterval, editSetText, tvFullScreen, tvScreenLight;
private SeekBar seekBar; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main); seekBar = (SeekBar) findViewById(R.id.seekBar);
seekBar.setMax(100); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub } public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub } public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = (float) (progress / 100.0);
getWindow().setAttributes(lp);
}
}); ll = (LinearLayout) findViewById(R.id.root);
ll.setBackgroundColor(0XFFFFFFFF); btnTimeInterval = (Button) findViewById(R.id.btnTimeInterval);
btnSetText = (Button) findViewById(R.id.btnSetText); etTimeInterval = (TextView) findViewById(R.id.etTimeInterval);
editSetText = (TextView) findViewById(R.id.editSetText);
tvFullScreen = (TextView) findViewById(R.id.tvFullScreen);
tvScreenLight = (TextView) findViewById(R.id.tvScreenLight); final Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
redColor = (int) (80 + Math.random() * 175);
blueColor = (int) (80 + Math.random() * 175);
greenColor = (int) (80 + Math.random() * 175);
ll.setBackgroundColor(0xff000000 + redColor * 255 * 255
+ blueColor * 255 + greenColor);
break;
default:
break;
}
super.handleMessage(msg);
}
}; btnTimeInterval.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try {
if (etTimeInterval.getText() != null) {
setAllUiVisibilityGone();
tvFullScreen.setVisibility(8);
Timer timer = new Timer(true);
timer.schedule(task, 1000, Integer
.parseInt(etTimeInterval.getText().toString()));
} } catch (Exception e) { } }
}); btnSetText.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try {
if (editSetText.getText() != null) {
setAllUiVisibilityGone();
text = editSetText.getText().toString().toCharArray();
tvFullScreen.setBackgroundColor(0xff000000);
ll.setBackgroundColor(0xff000000);
enableView = true;
} } catch (Exception e) {
// TODO: handle exception
}
}
}); ll.setOnClickListener(new View.OnClickListener() { public void onClick(View v) {
if (enableView == true) {
clickTimes++;
if (clickTimes % 2 == 1) {
tvFullScreen.setBackgroundColor(0xff000000);
ll.setBackgroundColor(0xff000000); tvRotation = (int) (45 + Math.random() * 90);
tvFullScreen.setRotation(tvRotation); tvRedColor = (int) (100 + Math.random() * 155);
tvBlueColor = (int) (100 + Math.random() * 155);
tvGreenColor = (int) (100 + Math.random() * 155);
tvFullScreen.setTextColor(0xff000000 + tvRedColor * 255
* 255 + tvBlueColor * 255 + tvGreenColor); if (i < text.length) {
tvFullScreen.setText(text, i++, 1);
} else {
tvFullScreen.setTextColor(0xff000000);
} } else {
tvFullScreen.setBackgroundColor(0xff000000);
tvFullScreen.setTextColor(0xff000000);
ll.setBackgroundColor(0xff000000);
}
}
}
}); task = new TimerTask() { @Override
public void run() {
Message message = new Message();
message.what = 1;
handler.sendMessage(message);
}
}; } public void setAllUiVisibilityGone() {
btnTimeInterval.setVisibility(8);
etTimeInterval.setVisibility(8);
btnSetText.setVisibility(8);
editSetText.setVisibility(8);
seekBar.setVisibility(8);
tvScreenLight.setVisibility(8);
}
}

MainActivity

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffffff"
android:orientation="vertical"
tools:context="com.example.raw.MainActivity" > <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <EditText
android:id="@+id/etTimeInterval"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:ems="10"
android:hint="输入时间间隔"
android:inputType="numberDecimal" > <requestFocus />
</EditText> <Button
android:id="@+id/btnTimeInterval"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="设定间隔" />
</LinearLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <EditText
android:id="@+id/editSetText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:ems="10"
android:hint="输入文字" /> <Button
android:id="@+id/btnSetText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="设定文字" />
</LinearLayout> <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" > <SeekBar
android:id="@+id/seekBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="2" /> <TextView
android:id="@+id/tvScreenLight"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="屏幕亮度"
android:layout_weight="3"
android:gravity="center"
android:textSize="20sp"/>
</LinearLayout> <TextView
android:id="@+id/tvFullScreen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:text=""
android:textSize="280sp" /> </LinearLayout>

XML文件

19_B门长时曝光APP的更多相关文章

  1. 背水一战 Windows 10 (104) - 通知(Toast): 纯文本 toast, 短时 toast, 长时 toast, 图文 toast

    [源码下载] 背水一战 Windows 10 (104) - 通知(Toast): 纯文本 toast, 短时 toast, 长时 toast, 图文 toast 作者:webabcd 介绍背水一战 ...

  2. html中使用js实现内容过长时部分

    有时数据内容太长时我们并不希望其全部显示出来,因为这样可能会导致用于显示这些内容的标签被撑开影响美观. 这时就希望能够实现默认只显示部分内容,在鼠标放上去的时候再将全部的内容显示出来. 这里提供一个简 ...

  3. iOS设置文字过长时的显示格式

    以label为例: //设置文字过长时的显示格式 aLabel.lineBreakMode = UILineBreakModeMiddleTruncation; //截去中间 aLabel.lineB ...

  4. HTML中文本过长时自动隐藏末尾部分或中间等任意部分

    一.    一般情况下,HTML字符串过长时都会将超过的部分隐藏点,方法如下: 设置CSS: .ellipsis-type{ max-width: 50px;                      ...

  5. c# c/s 框架读取的配置文件时是app.exe.config

    c# c/s 框架读取的配置文件时是app.exe.config, 一般在bin中间中俄debug中或者Release中

  6. echarts pie 图表当名称太长时

    当饼图的名称太长时,只显示几个字符,其余的... let use; use.setOption({ tooltip: { trigger: 'item', formatter: "{a} & ...

  7. 返回xml过长时被nginx截断的解决办法

    返回xml过长时被nginx截断的解决办法 问题描述:通过网页获取数据,数据格式为xml.当xml比较短时,可以正常获取数据.但是xml长度过长时不能正常获取数据,通过观察返回数据的源代码,发现xml ...

  8. UILabel标签文字过长时的显示方式

    lineBreakMode:设置标签文字过长时的显示方式. label.lineBreakMode = NSLineBreakByCharWrapping; //以字符为显示单位显示,后面部分省略不显 ...

  9. 当td中文字过长时,显示为省略号

    当表格中的文字过长时,可选择已省略号显示.这里是用js实现的.首先获取td中的文字长度(innerText.length),如果长度超过了设定的长度,则截取内容,加上省略号显示.示例代码如下: $(f ...

随机推荐

  1. MyBatis 原理浅析——基本原理

    前言 MyBatis 是一个被广泛应用的持久化框架.一个简单的使用示例如下所示,先创建会话工厂,然后从会话工厂中打开会话,通过 class 类型和配置生成 Mapper 接口的代理实现,最后使用 Ma ...

  2. 【漏洞复现】Shiro<=1.2.4反序列化漏洞

    0x01 概述 Shiro简介 Apache Shiro是一个强大且易用的Java安全框架,执行身份验证.授权.密码和会话管理.使用Shiro的易于理解的API,您可以快速.轻松地获得任何应用程序,从 ...

  3. iOS面试高薪,进阶 你会这些呢嘛?(持续更新中)

    这个栏目将持续更新--请iOS的小伙伴关注!做这个的初心是希望能巩固自己的基础知识,当然也希望能帮助更多的开发者! 基础>分析>总结 面试 iOS常见基础面试题(附参考答案) iOS底层原 ...

  4. 利用MultipartFile来进行文件上传

    这个例子实在SpringMVC的基础上完成的,因此在web.xml中需要配置 web.xml <!-- 配置Spring MVC的入口 DispatcherServlet,把所有的请求都提交到该 ...

  5. js try catch 获取错误信息

    try{ alert(i); }catch(e){ console.log(e.message,e.name,e.lineNumber) } message -- 错误提示信息 fileName -- ...

  6. RPA小结

    1--怎么理解RPA? 1)RPA就是机器人流程自动化,根据业务的固定规则,自动完成一些任务(如数据抓取,信息录入,数据处理,自动化运维等),替代人类的重复劳动, 但RPA的发展已经不仅仅满足于此,正 ...

  7. [MIT6.006] 22. Daynamic Programming IV: Guitar Fingering, Tetris, Super Mario Bro. 动态规划IV:吉他指弹,俄罗斯方块,超级玛丽奥

    之前我们讲到动态规划五步中有个Guessing猜,一般情况下猜有两种情况: 在猜和递归上:猜的是用于解决更大问题的子问题: 在子问题定义上:如果要猜更多,就要增加更多子问题. 下面我们来看如果像背包问 ...

  8. 服务和进程管理及查看分区和cpu

    查看分区:cat /proc/partitions   [root@lbg init.d]# cat /proc/partitions major minor  #blocks  name       ...

  9. php 数据转储Excel文件

    1.下载PHPExcel文件 下载地址:https://www.php.cn/xiazai/leiku/1491 2.在php写入以下代码,执行即可 $arr = Db::name('user')-& ...

  10. 企业级工作流解决方案(十五)--集成Abp和ng-alain--Abp其他改造

    配置功能增强 Abp定义了各种配置接口,但是没有定义这些配置数据从哪里来,但是管理配置数据对于一个应用程序来说,是必不可少的一件事情. .net的配置数据管理,一般放在Web.config文件或者Ap ...