In the previous article "men are on the fifth layer [Fifth Layer] -- skin-changing version of 100 games", Sun Xiaoqiang implemented 2048 games in his own way and shared the core source code, this sunny Xiaoqiang intends to publish all the source code of the project and use this example to introduce how to add advertisements and implement sharing functions in this article.
The final running effect is as follows (for more running effects, see "is a man's next layer 100 [Fifth Layer] -- skin swap version 2048 game"):
I. The idea of skin replacement is actually very simple. Add a menu in the actionbar. After you select a skin, modify the current skin status and save it to sharedpreference, this allows you to read the skin directly after startup, create a bitmap object for the skin, and draw it in ondraw.
private void changeSkin(int skin) {Editor edit = sharedPreference.edit();edit.putInt("skin", skin);edit.commit();my2048View.changeSkin(skin);}
public void changeSkin(int skin){this.skin = skin;switch (skin) {case 0:for(int i=0; i<bitmaps.length; i++){bitmaps[i] = null;}for(int i=0; i<bitmaps_skin3.length; i++){bitmaps_skin3[i] = null;}break;case 1:for(int i=0; i<bitmaps_skin3.length; i++){bitmaps_skin3[i] = null;}initBitmap();break;case 2:for(int i=0; i<bitmaps.length; i++){bitmaps[i] = null;}initBitmap();break;}invalidate();}
2. How to add an advertisement some friends may ask before adding an advertisement. Which advertisement platform is better? I don't know the answer to this question. Before that, Sun Xiaoqiang never added advertisements to the app. This time, I just tried to use rice ads first, finally, I switched to jumi's advertisement (I personally think that jumi's advertising revenue is slightly higher ). In fact, the ad Integration Methods for various platforms are basically similar. Let's take a look at how the ads of jumi integrate:
I first selected the official unified push package, after integration found that 360 is easy to detect, and later changed to the custom push method (official documentation is very detailed: http://www.adjumi.com/AppDevPlat/Page/SDKSm.aspx ), I will not explain it step by step here. Remember to turn on the advertisement:
The next thing we will do is very simple. Let's take a look at our own benefits over a period of time.
3. There are two ways to add the sharing function. One is to start the analysis component of the system (the interface is difficult to modify and control ), the other is to use third-party analysis components (easy to customize, beautiful interface, recommended ). The first method is implemented as follows:
@ Overridepublic void onclick (view arg0) {/* my2048view. savemaxscore (); intent = new intent (intent. action_send); intent. settype ("image/*"); intent. putextra (intent. extra_subject, "2048 LOL"); // intent. putextra (intent. extra_stream, Uri. fromfile (new file ("Android: Resource: // COM. example. my2048/"+ R. raw. required _img); intent. putextra (intent. extra_text, "My highest record is" + sharedpreference. getint ("maxscore", 0) + "Points, come and have fun, lol version 2048! Youmu youzhe ~~, Go in and see the http://blog.csdn.net/dawanganban/article/details/37863693 "); intent. setflags (intent. flag_activity_new_task); startactivity (intent. createchooser (intent, gettitle (); * // whether the sharing selection page is my2048view only for logged-on users. savemaxscore (); mcontroller. openshare (mainactivity. this, false );}
The second way to achieve a variety of platforms available (here choose umeng) first registered as umeng developers, and get umeng appkey umeng to share the help documentation (http://dev.umeng.com/social/android/share/quick-integration ), before sharing, you need to make some preparations and apply for an appkey from each sharing platform.
Please refer to umeng's API for details. (This is a bit of a discussion. The API documentation is too bad ~~) Umeng has three integration methods. I chose the second method officially recommended, so I need to introduce an external project (for shared projects ), and the project is stored in the same directory as the project. Umeng's social sharing component project (GIT used in the project: [email protected]: lxq_xsyu/social_sdk_library_project.git). Note the Path Problem When obfuscation occurs:-libraryjars .. /social_sdk_library_project/libs/socialsdk_qqzone_2.jar 4. Download the complete source code. For details and better methods, refer to this project. I will paste all the source code of the project (note: please use the GIT tool to download and download the above shared component project usage instructions to add)
Git: [email protected]: lxq_xsyu/my2048.git code: Success? ArticleID = 37863693
If you have any questions, please leave a message below ~~ If Sun Xiaoqiang sees it, he will reply in time.