Not Fibonacci(矩阵连乘)
992
2022-08-06
用eclipse制作一个属于程序员浪漫的表白代码(最浪漫的表白编程代码)
有多少人是借着真心话大冒险去和喜欢的人表白的看看,本文就教大家使用eclipse逗逗妹子,表白一下吧
先秀一下效果吧
可以使用手机进行录制屏幕或者转gif
开发工具使用eclipse
代码如下:
MainActivity.java
public class MainActivity extends ListActivity implements BaseSliderView.OnSliderClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//初始化图片切换
initChangePicture();
//初始化音乐
initMusic();
//初始化文字展示
initWord();
}
@Override
public void onSliderClick(BaseSliderView slider) {
Toast.makeText(this, slider.getBundle().get("extra") + "",Toast.LENGTH_SHORT).show();
}
private SliderLayout mDemoSlider;
private void initChangePicture(){
mDemoSlider = (SliderLayout)findViewById(R.id.slider);
//两种方式加载数据
//加载本地
HashMap
url_maps.put("GitOnWay", "http://gitonway.blog.163.com/");
//加载网络
HashMap
file_maps.put("love-A",R.drawable.a);
file_maps.put("love-B",R.drawable.b);
file_maps.put("love-C",R.drawable.c);
file_maps.put("love-D", R.drawable.d);
for(String name : file_maps.keySet()){
TextSliderView textSliderView = new TextSliderView(this);
// 初始化幻灯片页面
textSliderView
.description(name)
.image(file_maps.get(name))
.setOnSliderClickListener(this);
//添加要传递的数据
textSliderView.getBundle()
.putString("extra",name);
mDemoSlider.addSlider(textSliderView);
}
// 幻灯片切换方式
mDemoSlider.setPresetTransformer(SliderLayout.Transformer.Accordion);
// 指示符位置
mDemoSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
// 定义指示器样式
// mDemoSlider.setCustomIndicator(your view);
// 幻灯片循环
// mDemoSlider.startAutoCycle();
// 停止循环
mDemoSlider.stopAutoCycle();
// 设置指示器的显示与否
mDemoSlider.setIndicatorVisibility(PagerIndicator.IndicatorVisibility.Visible);
// 设置幻灯片的转化时间
// mDemoSlider.setSliderTransformDuration(5000, null);
// 用来自定义幻灯片标题的显示方式
mDemoSlider.setCustomAnimation(new DescriptionAnimation());
// 幻灯片切换时间
mDemoSlider.setDuration(3000);
// 实现随机切换
TimerTask task = new TimerTask() {
@Override
public void run() {
Transformer[] tranformers = SliderLayout.Transformer.values();
Transformer transformer = tranformers[(int) (Math.random() * tranformers.length)];
mDemoSlider.setPresetTransformer(transformer);
}
};
new Timer().schedule(task, 2000, 2000);
}
//res/raw中的音乐文件资源映射
private Map
//播放对象
private MediaPlayer myMediaPlayer;
//播放列表
private List
//当前播放歌曲的索引
private int currentListItem=0;
//音乐的路径, 如果存在sd卡,则使用sd卡,否则使用内存中的data目录
private static String MUSIC_PATH = hasSDCardMounted() ? new String(Environment.getExternalStorageDirectory().getAbsolutePath() + "/hjz/")
: null;
private void initMusic(){
myMediaPlayer=new MediaPlayer();
findView();
musicList();
listener();
//自动播放第一首歌
if(myMusicList.size() > 0){
playMusic(MUSIC_PATH, myMusicList.get(currentListItem));
}
}
public static boolean hasSDCardMounted() {
String state = Environment.getExternalStorageState();
if (state != null && state.equals(Environment.MEDIA_MOUNTED)) {
return true;
} else {
return false;
}
}
//绑定音乐
private void musicList(){
try {
File home = new File(MUSIC_PATH);
//如果有sd卡,但是sd卡中没有指定的音乐文件夹,则采用项目中的音乐文件
if(MUSIC_PATH == null || home.listFiles() == null) {//绑定 res/raw下的音乐文件
MUSIC_PATH = null;
musicPath = new HashMap
musicPath.put("杨宗纬 - 一次就好.mp3", R.raw.yi_ci_jiu_hao);
musicPath.put("霍建华,赵丽颖 - 不可说.mp3", R.raw.bu_ke_shuo);
musicPath.put("川井憲次 - 孤独な巡礼.mp3", R.raw.gu_du_xun_li);
myMusicList.addAll(musicPath.keySet());
} else {
Log.v("MUSIC_PATH", MUSIC_PATH);
if(home.listFiles(new MusicFilter()).length>0){
for(File file:home.listFiles(new MusicFilter())){
myMusicList.add(file.getName());
}
}
}
if(myMusicList.size() > 0) {
ArrayAdapter
setListAdapter(musicList);
}
} catch (Exception e) {
Log.e("获取音乐文件出错:", e.toString());
}
}
//获取按钮
void findView(){
viewHolder.start=(Button)findViewById(R.id.start);
viewHolder.stop=(Button)findViewById(R.id.stop);
viewHolder.next=(Button)findViewById(R.id.next);
viewHolder.pause=(Button)findViewById(R.id.pause);
viewHolder.last=(Button)findViewById(R.id.last);
}
//监听事件
void listener(){
//停止
viewHolder.stop.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(myMediaPlayer.isPlaying()){
myMediaPlayer.reset();
}
}
});
//开始
viewHolder.start.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(myMusicList.size() == 0) return;
playMusic(MUSIC_PATH, myMusicList.get(currentListItem));
}
});
//下一首
viewHolder.next.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
nextMusic();
}
});
//暂停
viewHolder.pause.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(myMusicList.size() == 0) return;
if(myMediaPlayer.isPlaying()){
myMediaPlayer.pause();
}else{
myMediaPlayer.start();
}
}
});
//上一首
viewHolder.last.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
lastMusic();
}
});
}
//播放音乐
void playMusic(String basePath, String path){
try {
if(basePath != null) {
myMediaPlayer.reset();
myMediaPlayer.setDataSource(basePath+path);
myMediaPlayer.prepare();
} else {
myMediaPlayer.pause();
myMediaPlayer.release();
myMediaPlayer = MediaPlayer.create(MainActivity.this, musicPath.get(path));
}
myMediaPlayer.start();
myMediaPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
nextMusic();
}
});
} catch (Exception e) {
Log.e("播放sd卡音乐失败", e.toString());
e.printStackTrace();
}
}
//下一首
void nextMusic(){
if(myMusicList.size() > 0) {
if(++currentListItem>=myMusicList.size()){
currentListItem=0;
}
playMusic(MUSIC_PATH, myMusicList.get(currentListItem));
}
}
//上一首
void lastMusic(){
if(myMusicList.size() > 0) {
if(currentListItem!=0) {
playMusic(MUSIC_PATH, myMusicList.get(--currentListItem));
} else{
playMusic(MUSIC_PATH, myMusicList.get(currentListItem=myMusicList.size()-1));
}
}
}
//当用户返回时结束音乐并释放音乐对象
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode==KeyEvent.KEYCODE_BACK){
myMediaPlayer.stop();
myMediaPlayer.release();
this.finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
//当选择列表项时播放音乐
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
currentListItem=position;
playMusic(MUSIC_PATH, myMusicList.get(currentListItem));
}
//初始化文字展示
private TextSurface textSurface;
private void initWord(){
LinearLayout layout = (LinearLayout) findViewById(R.id.LinearLayoutWord);//找到你要设透明背景的layout 的id
layout.getBackground().setAlpha(60);//0~255透明度值
textSurface = (TextSurface) findViewById(R.id.text_surface);
textSurface.postDelayed(new Runnable() {
@Override public void run() {
show();
}
}, 1000);
}
private void show() {
textSurface.reset();
List
animationsSets.add(CookieThumperSample.getCookieThumperAnimations(getAssets()));
animationsSets.addAll(SlideSample.getSlideAnimations(getContents()));
textSurface.play(TYPE.SEQUENTIAL, animationsSets.toArray(new AnimationsSet[]{}));
// ColorSample.play(textSurface);
// AlignSample.play(textSurface);
// Rotation3DSample.play(textSurface);
// ScaleTextSample.run(textSurface);
// ShapeRevealLoopSample.play(textSurface);
// ShapeRevealSample.play(textSurface);
// SlideSample.play(textSurface);
// SurfaceScaleSample.play(textSurface);
// SurfaceTransSample.play(textSurface);
}
private List
List
try{
//得到资源中的asset数据流
String fileName = "content.txt"; //文件名字
String res="";
InputStream in = getResources().getAssets().open(fileName);
int length = in.available();
byte [] buffer = new byte[length];
in.read(buffer);
in.close();
res = EncodingUtils.getString(buffer, "UTF-8");
String[] strings = res.split("[,|,|\\.|。]");
int len = strings.length/4 * 4;
for(int i=0; i < len; ++i)
contents.add(strings[i]);
}catch(Exception e){
e.printStackTrace();
Log.e("getContents", e.toString());
}
return contents;
}
}
activity_main.xml(页面布局)
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:custom="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.gitonway.androidimagesliderdemo.activity.MainActivity"> android:orientation="vertical" android:layout_weight="3" android:layout_height="fill_parent" android:layout_width="match_parent"> android:id="@+id/slider" android:layout_width="match_parent" android:layout_height="fill_parent" custom:pager_animation="Accordion" custom:auto_cycle="true" custom:indicator_visibility="visible" custom:pager_animation_span="1100"/> android:layout_weight="3" android:layout_height="fill_parent" android:orientation="vertical" android:background="@android:color/background_dark" android:layout_width="match_parent"> android:id="@+id/text_surface" android:layout_height="fill_parent" android:layout_width="match_parent"/> android:id="@+id/LinearLayoutMusic" android:layout_width="match_parent" android:layout_weight="4" android:layout_height="fill_parent" android:orientation="vertical" > android:id="@id/android:list" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="fill_parent" android:scrollbars="vertical" /> android:id="@+id/bottomBtn" android:layout_width="match_parent" android:layout_height="60dp" android:gravity="center|center_horizontal|center_vertical" android:orientation="horizontal" >
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.gitonway.androidimagesliderdemo.activity.MainActivity">
android:orientation="vertical" android:layout_weight="3" android:layout_height="fill_parent" android:layout_width="match_parent"> android:id="@+id/slider" android:layout_width="match_parent" android:layout_height="fill_parent" custom:pager_animation="Accordion" custom:auto_cycle="true" custom:indicator_visibility="visible" custom:pager_animation_span="1100"/>
android:orientation="vertical"
android:layout_weight="3"
android:layout_height="fill_parent"
android:layout_width="match_parent">
android:id="@+id/slider" android:layout_width="match_parent" android:layout_height="fill_parent" custom:pager_animation="Accordion" custom:auto_cycle="true" custom:indicator_visibility="visible" custom:pager_animation_span="1100"/>
android:id="@+id/slider"
android:layout_width="match_parent"
android:layout_height="fill_parent"
custom:pager_animation="Accordion"
custom:auto_cycle="true"
custom:indicator_visibility="visible"
custom:pager_animation_span="1100"/>
android:layout_weight="3" android:layout_height="fill_parent" android:orientation="vertical" android:background="@android:color/background_dark" android:layout_width="match_parent"> android:id="@+id/text_surface" android:layout_height="fill_parent" android:layout_width="match_parent"/>
android:layout_weight="3"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@android:color/background_dark"
android:layout_width="match_parent">
android:id="@+id/text_surface" android:layout_height="fill_parent" android:layout_width="match_parent"/>
android:id="@+id/text_surface"
android:layout_height="fill_parent"
android:layout_width="match_parent"/>
android:id="@+id/LinearLayoutMusic" android:layout_width="match_parent" android:layout_weight="4" android:layout_height="fill_parent" android:orientation="vertical" > android:id="@id/android:list" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="fill_parent" android:scrollbars="vertical" /> android:id="@+id/bottomBtn" android:layout_width="match_parent" android:layout_height="60dp" android:gravity="center|center_horizontal|center_vertical" android:orientation="horizontal" >
android:id="@+id/LinearLayoutMusic"
android:layout_width="match_parent"
android:layout_weight="4"
android:layout_height="fill_parent"
android:orientation="vertical" >
android:id="@id/android:list" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="fill_parent" android:scrollbars="vertical" /> android:id="@+id/bottomBtn" android:layout_width="match_parent" android:layout_height="60dp" android:gravity="center|center_horizontal|center_vertical" android:orientation="horizontal" >
android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:scrollbars="vertical" />
android:id="@+id/bottomBtn" android:layout_width="match_parent" android:layout_height="60dp" android:gravity="center|center_horizontal|center_vertical" android:orientation="horizontal" >
android:id="@+id/bottomBtn"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center|center_horizontal|center_vertical"
android:orientation="horizontal" >
android:background="@drawable/last"
android:layout_width="wrap_content" android:layout_height="wrap_content">
android:background="@drawable/stop"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content" android:layout_height="wrap_content">
android:background="@drawable/start"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content" android:layout_height="wrap_content">
android:background="@drawable/pause"
android:layout_marginLeft="10dp"
android:layout_height="wrap_content">
android:background="@drawable/next"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content" android:layout_height="wrap_content">
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~