android表白app
一、前言
馬上就要520和521了,是不是還有像我一樣的單身狗啊。我就知道有,所以這兩天簡(jiǎn)單寫(xiě)了這個(gè)小程序(其實(shí)是替別人寫(xiě)的),雖然我并不會(huì)用去騙女孩子(因?yàn)樽罱α?#xff0c;實(shí)習(xí)完之后要搞畢設(shè),要搞論文啊,誰(shuí)能幫幫我...),但是我想很多人肯定會(huì)感興趣吧。如果你感興趣就拿去逗妹子一樂(lè)吧。
如果你很感興趣,你可以在我寫(xiě)的基礎(chǔ)上增輝加彩,或者根據(jù)我提供的資源自己動(dòng)手,嘗試一下。
二、先show一下效果
?
?
三、Android手機(jī)如何錄制屏幕及轉(zhuǎn)GIF
https://www.aswifter.com/2015/07/10/android-record-video-to-gif/
第一次試的時(shí)候沒(méi)有成功,第二次設(shè)定屏幕分辨率后成功了,但是效果太差。果斷又試了第三次,成功了,手機(jī)根目錄出現(xiàn)了剛剛錄制的視屏文件。
adb pull 會(huì)把文件從手機(jī)上復(fù)制到本地(ANDROID_SDK_HOME/platform-tools目錄下,也就是adb.exe所在的目錄)
接著就是轉(zhuǎn)換成gif了,這里我用PS處理
然后文件——》存儲(chǔ)為web所有格式——》選擇gif。如果gif過(guò)大,可能會(huì)導(dǎo)致ps崩潰,簡(jiǎn)單的做法就是調(diào)整圖片的大小,就可以了。
四、下載地址
apk文件:https://github.com/hjzgg/LoveDemo/tree/master/bin
項(xiàng)目:https://github.com/hjzgg/LoveDemo
五、技術(shù)路線,分享我的制作過(guò)程
1.準(zhǔn)備
大二的時(shí)候搞過(guò)一段時(shí)間的android,時(shí)隔一年半,好多東西都忘了,不過(guò)現(xiàn)在撿起來(lái)也不晚。
開(kāi)發(fā)工具使用eclipse或者android studio。我使用的eclipse,那么就要自己去安裝ADT和SDK了,安裝的時(shí)間有點(diǎn)蛋疼啊。
2.資源收集
作為一個(gè)表白程序,必須要有圖片吧,文字吧, 最好加上背景音樂(lè)吧,不然就真的沒(méi)有意思了。下面分享幾個(gè)資源鏈接:
文字特效:?https://github.com/elevenetc/TextSurface
圖片切花特效:?https://github.com/daimajia/AndroidImageSlider
音樂(lè)播放器:?http://www.cnblogs.com/TerryBlog/archive/2010/06/26/1765910.html
先說(shuō)一下文字特效,將文字特效的代碼下載下來(lái)后,所有的演示代碼放在了\app\src\main\java\su\levenetc\android\textsurface\sample\checks這里面,app\src\main\java\su\levenetc\android\textsurface\sample\SampleActivity.java是app入口activity。最主要的代碼放在了library目錄下,需要將library\src\main下面的文件復(fù)制到我們的項(xiàng)目中,參考入口activity的內(nèi)容進(jìn)行調(diào)用就可以了。?資源中提供了很多文字展示的效果,本人愚鈍,只用了兩個(gè),而且用的不是太好。我主要增加了文字處理,效果結(jié)合的功能。將要展示的文字按照4句劃分,然后調(diào)用文字效果展示。文字資源放在了assets文件夾下面。
圖片切換特效很好用,進(jìn)本不要改動(dòng),直接把圖片換了就行了,效果不錯(cuò)。
音樂(lè)播放器引用網(wǎng)上的一位哥們兒的,寫(xiě)的簡(jiǎn)介靠譜,這里直接拿來(lái)用了,用的是MediaPlayer進(jìn)行音樂(lè)播放。我改了一些地方,里面有點(diǎn)兒小bug。增加了一個(gè)功能,就是在sd卡不存在的時(shí)候(無(wú)論是內(nèi)置的還是外置的),依然可以獲取到音樂(lè)文件,考慮了好多方式,比如直接調(diào)用網(wǎng)上的,或者調(diào)用手機(jī)內(nèi)存中的...,想了想還是將音樂(lè)文件放在項(xiàng)目當(dāng)中了,可以放在res/raw下,也可以放在assets下,各有好處,本人放在了res/raw目錄下。還有一個(gè)要注意的是判斷手機(jī)的sd卡環(huán)境是否可以使用。具體的還是看代碼吧。
3.主要代碼
說(shuō)了這么多,最主要的代碼都是在一個(gè)activity中,代碼如下:
MainActivity.java
public class MainActivity extends ListActivity implements BaseSliderView.OnSliderClickListener{@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//初始化圖片切換 initChangePicture();//初始化音樂(lè) initMusic();//初始化文字展示 initWord();}@Overridepublic 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);//兩種方式加載數(shù)據(jù)//加載本地HashMap<String,String> url_maps = new HashMap<String, String>();url_maps.put("GitOnWay", "http://gitonway.blog.163.com/");//加載網(wǎng)絡(luò)HashMap<String,Integer> file_maps = new HashMap<String, Integer>();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);// 初始化幻燈片頁(yè)面 textSliderView.description(name).image(file_maps.get(name)).setOnSliderClickListener(this);//添加要傳遞的數(shù)據(jù) textSliderView.getBundle().putString("extra",name);mDemoSlider.addSlider(textSliderView);}// 幻燈片切換方式 mDemoSlider.setPresetTransformer(SliderLayout.Transformer.Accordion); // 指示符位置 mDemoSlider.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom); // 定義指示器樣式 // mDemoSlider.setCustomIndicator(your view); // 幻燈片循環(huán) // mDemoSlider.startAutoCycle(); // 停止循環(huán) mDemoSlider.stopAutoCycle(); // 設(shè)置指示器的顯示與否 mDemoSlider.setIndicatorVisibility(PagerIndicator.IndicatorVisibility.Visible); // 設(shè)置幻燈片的轉(zhuǎn)化時(shí)間 // mDemoSlider.setSliderTransformDuration(5000, null); // 用來(lái)自定義幻燈片標(biāo)題的顯示方式 mDemoSlider.setCustomAnimation(new DescriptionAnimation()); // 幻燈片切換時(shí)間 mDemoSlider.setDuration(3000);// 實(shí)現(xiàn)隨機(jī)切換TimerTask task = new TimerTask() {@Overridepublic 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中的音樂(lè)文件資源映射private Map<String, Integer> musicPath;//播放對(duì)象private MediaPlayer myMediaPlayer;//播放列表private List<String> myMusicList = new ArrayList<String>();//當(dāng)前播放歌曲的索引private int currentListItem=0;//音樂(lè)的路徑, 如果存在sd卡,則使用sd卡,否則使用內(nèi)存中的data目錄private static String MUSIC_PATH = hasSDCardMounted() ? new String(Environment.getExternalStorageDirectory().getAbsolutePath() + "/hjz/"): null;private void initMusic(){myMediaPlayer=new MediaPlayer();findView();musicList();listener();//自動(dòng)播放第一首歌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;}}//綁定音樂(lè)private void musicList(){try {File home = new File(MUSIC_PATH);//如果有sd卡,但是sd卡中沒(méi)有指定的音樂(lè)文件夾,則采用項(xiàng)目中的音樂(lè)文件if(MUSIC_PATH == null || home.listFiles() == null) {//綁定 res/raw下的音樂(lè)文件MUSIC_PATH = null;musicPath = new HashMap<String, Integer>();musicPath.put("楊宗緯 - 一次就好.mp3", R.raw.yi_ci_jiu_hao);musicPath.put("霍建華,趙麗穎 - 不可說(shuō).mp3", R.raw.bu_ke_shuo);musicPath.put("川井憲次 - 孤獨(dú)な巡禮.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<String> musicList = new ArrayAdapter<String>(MainActivity.this, R.layout.musicitme, myMusicList);setListAdapter(musicList);}} catch (Exception e) {Log.e("獲取音樂(lè)文件出錯(cuò):", 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);}//監(jiān)聽(tīng)事件void listener(){//停止viewHolder.stop.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {// TODO Auto-generated method stubif(myMediaPlayer.isPlaying()){myMediaPlayer.reset();}}});//開(kāi)始viewHolder.start.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {if(myMusicList.size() == 0) return;playMusic(MUSIC_PATH, myMusicList.get(currentListItem));}});//下一首viewHolder.next.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {nextMusic();}});//暫停viewHolder.pause.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {if(myMusicList.size() == 0) return;if(myMediaPlayer.isPlaying()){myMediaPlayer.pause();}else{myMediaPlayer.start();}}});//上一首viewHolder.last.setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {lastMusic();}});}//播放音樂(lè) 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() {@Overridepublic void onCompletion(MediaPlayer mp) {nextMusic();}});} catch (Exception e) {Log.e("播放sd卡音樂(lè)失敗", 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));}}}//當(dāng)用戶(hù)返回時(shí)結(jié)束音樂(lè)并釋放音樂(lè)對(duì)象 @Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if(keyCode==KeyEvent.KEYCODE_BACK){myMediaPlayer.stop();myMediaPlayer.release();this.finish();return true;}return super.onKeyDown(keyCode, event);}//當(dāng)選擇列表項(xiàng)時(shí)播放音樂(lè) @Overrideprotected 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);//找到你要設(shè)透明背景的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<AnimationsSet> animationsSets = new ArrayList<AnimationsSet>();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<String> getContents(){List<String> contents = new ArrayList<String>();try{ //得到資源中的asset數(shù)據(jù)流 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(頁(yè)面布局)
<LinearLayoutxmlns: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"><LinearLayout android:id="@+id/LinearLayoutPicture"android:orientation="vertical"android:layout_weight="3"android:layout_height="fill_parent"android:layout_width="match_parent"><!-- 圖片切換 --><com.gitonway.androidimagesliderdemo.widget.imageslider.SliderLayoutandroid: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"/><!-- <com.gitonway.androidimagesliderdemo.widget.imageslider.Indicators.PagerIndicatorandroid:id="@+id/custom_indicator"android:layout_width="wrap_content"android:layout_height="wrap_content"android:gravity="center"custom:selected_color="#0095BF"custom:unselected_color="#55333333"custom:selected_drawable="@drawable/ic_launcher"custom:shape="oval"custom:selected_padding_left="6dp"custom:selected_padding_right="6dp"custom:unselected_padding_left="2dp"custom:unselected_padding_right="2dp"android:layout_centerHorizontal="true"android:layout_alignParentBottom="true"custom:selected_width="6dp"custom:selected_height="6dp"custom:unselected_width="6dp"custom:unselected_height="6dp"android:layout_marginBottom="20dp"/><com.gitonway.androidimagesliderdemo.widget.imageslider.Indicators.PagerIndicatorandroid:id="@+id/custom_indicator2"style="@style/AndroidImageSlider_Corner_Oval_Orange"android:layout_centerHorizontal="true"android:layout_alignParentBottom="true"android:layout_marginBottom="20dp"/> --></LinearLayout><!-- 文字展現(xiàn) --><LinearLayout android:id="@+id/LinearLayoutWord"android:layout_weight="3"android:layout_height="fill_parent"android:orientation="vertical"android:background="@android:color/background_dark"android:layout_width="match_parent"><com.textsurface.TextSurfaceandroid:id="@+id/text_surface"android:layout_height="fill_parent"android:layout_width="match_parent"/></LinearLayout><!-- 音樂(lè)播放器 --><LinearLayoutandroid:id="@+id/LinearLayoutMusic"android:layout_width="match_parent"android:layout_weight="4"android:layout_height="fill_parent"android:orientation="vertical" ><ListViewandroid:id="@id/android:list"android:layout_width="match_parent"android:layout_weight="1"android:layout_height="fill_parent"android:scrollbars="vertical" /><LinearLayoutandroid:id="@+id/bottomBtn"android:layout_width="match_parent"android:layout_height="60dp"android:gravity="center|center_horizontal|center_vertical"android:orientation="horizontal" ><Button android:id="@+id/last" android:background="@drawable/last"android:layout_width="wrap_content" android:layout_height="wrap_content"></Button><Button android:id="@+id/stop"android:background="@drawable/stop"android:layout_marginLeft="10dp"android:layout_width="wrap_content" android:layout_height="wrap_content"></Button><Button android:id="@+id/start" android:background="@drawable/start"android:layout_marginLeft="10dp"android:layout_width="wrap_content" android:layout_height="wrap_content"></Button><Button android:id="@+id/pause" android:layout_width="wrap_content"android:background="@drawable/pause"android:layout_marginLeft="10dp"android:layout_height="wrap_content"></Button><Button android:id="@+id/next"android:background="@drawable/next"android:layout_marginLeft="10dp"android:layout_width="wrap_content" android:layout_height="wrap_content"></Button></LinearLayout></LinearLayout></LinearLayout>?
轉(zhuǎn)載于:https://www.cnblogs.com/hujunzheng/p/5510151.html
總結(jié)
以上是生活随笔為你收集整理的android表白app的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 大灵猫在大熊猫国家公园成都片区内主要以什
- 下一篇: 洗衣液和洗衣粉可以混合一起用吗?