Main interface of Palm Express (2)

Source: Internet
Author: User

Overview

This is Fragment1 's second part of the Content slider bar, (the main effect is the faux QQ effect) using the Slidingmenu_librarygithub Open source control on GitHub

As follows:

The "1" content area is reduced with the advent of menus

The "2" side-by-side menu gives a feeling of being hidden behind the content, not dragged out.

The "3" side-slip menu has a zoom and transparency effect

Then is the simple Baidu map, and shake a shake show little knowledge


1. layout file

Include in Fragment1 's main layout file R.layout.activity_main <include layout= "@layout/left_slide"/>

Layout file is simple because the skid bar is just a ListView

<span style= "Font-family:microsoft yahei;font-size:14px;" ><?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/ Res/android "android:layout_width=" match_parent "android:layout_height=" match_parent "android:orientation=" vertic Al "> <imageview android:id=" @+id/header "android:layout_width=" Wrap_content "android:layout _height= "Wrap_content" android:padding= "10DP" android:layout_gravity= "Center_horizontal" android:src= "@drawable/slideledefheader"/> <listview android:id= "@+id/leftslide_list" Android:layout_width= "Ma Tch_parent "android:layout_height=" match_parent "android:layout_margintop=" 20DP "Android:cachecolorhi Nt= "#00000000" android:footerdividersenabled= "false" android:gravity= "Center_horizontal" android:list Selector= "@android: Color/transparent" > </ListView></LinearLayout></span> 

2. Slide-Slip Effect Realization Analysis

So how can we do it:

We can constantly change the size of the content area while sliding, how to change it? Throughout the course of the menu, we constantly record the ratio of the width of the menu display to its total width, a process from 0 to 1, then convert the 0~1 to 1~0.7 (assuming the content area shrinks to 0.7);

The above can already get 0 to 1 of this value, then the zoom and transparency animation is not easy;

We used the horizontalscrollview, and then horizontally placed the menu and content, how to let the menu can be hidden behind the content? In fact, it is relatively simple, in the course of the menu appears, constantly set the X-direction of the menu offset; 0 when completely hidden, 0.3, the hidden X-direction offset is 0.7 width

The main code is in Slidingmenu.java.

<span style= "Font-family:microsoft yahei;font-size:14px;" >/** * scrolling occurs when */@Overrideprotected void onscrollchanged (int l, int t, int oldl, int Oldt) {super.onscrollchanged (L, T, O LDL, Oldt); float scale = l * 1.0f/mmenuwidth;  1 ~ 0/** * Difference 1: Content area 1.0~0.7 Zoom effect scale:1.0~0.0 0.7 + 0.3 * Scale * * Difference 2: Menu offset needs to be modified * * Difference 3: Menu display with zoom and transparency change scale: 0.7 ~1.0 1.0-scale * 0.3 Transparency 0.6 ~ 1.0 0.6+ * 0.4 * (1-scale); * */float RightScale = 0.7f + 0.3f * scale;float Leftscale = 1.0f-scale * 0.3f;float leftalpha = 0.6f + 0.4f * (1-sca Le);//Call Property animation, set Translationxviewhelper.settranslationx (Mmenu, mmenuwidth * scale * 0.8f); Viewhelper.setscalex (Mmenu, Leftscale); Viewhelper.setscaley (Mmenu, Leftscale); Viewhelper.setalpha (Mmenu, Leftalpha);//Set the center point of the content's zoom viewhelper.setpivotx (mcontent, 0); Viewhelper.setpivoty (Mcontent, Mcontent.getheight ()/2); Viewhelper.setscalex (Mcontent, RightScale); Viewhelper.setscaley (Mcontent, RightScale);} </span> 



3. Baidu Map

About access to Baidu Map key and basic skills can be achieved please see my other blog entry Baidu map, the map part of the relatively simple, mainly inheriting the bdlocationlistener to achieve their own positioning (private class Mylocationlistener Implements Bdlocationlistener), then use a nearby search Mpoisearch
. Searchnearby (New Poinearbysearchoption ())
. Location (latlng). Keyword ("courier"). Radius (3000)
. Pagenum (0));

<span style= "Font-family:microsoft yahei;font-size:14px;" >package com.map;import android.app.activity;import Android.content.context;import android.os.Bundle;import Android.view.menu;import Android.view.menuitem;import Android.view.window;import Android.widget.Toast;import Com.baidu.location.bdlocation;import Com.baidu.location.bdlocationlistener;import Com.baidu.location.locationclient;import Com.baidu.location.locationclientoption;import Com.baidu.mapapi.sdkinitializer;import Com.baidu.mapapi.map.baidumap;import Com.baidu.mapapi.map.bitmapdescriptor;import Com.baidu.mapapi.map.bitmapdescriptorfactory;import Com.baidu.mapapi.map.mapstatusupdate;import Com.baidu.mapapi.map.mapstatusupdatefactory;import Com.baidu.mapapi.map.mapview;import Com.baidu.mapapi.map.mylocationconfiguration;import Com.baidu.mapapi.map.mylocationconfiguration.locationmode;import Com.baidu.mapapi.map.mylocationdata;import Com.baidu.mapapi.model.latlng;import Com.baidu.mapapi.overlayutil.poioverlay;import CoM.baidu.mapapi.search.core.cityinfo;import Com.baidu.mapapi.search.core.searchresult;import Com.baidu.mapapi.search.poi.ongetpoisearchresultlistener;import Com.baidu.mapapi.search.poi.PoiDetailResult; Import Com.baidu.mapapi.search.poi.poinearbysearchoption;import Com.baidu.mapapi.search.poi.poiresult;import Com.baidu.mapapi.search.poi.poisearch;import Com.baidu.mapapi.search.poi.poisorttype;import Com.map.myorientationlistener.onorientationlistener;import Com.weimeijing.feigeshudi.r;public class Baidu extends Activity {//define required controls private Mapview Mmapview = null;private Baidumap Mbaidumap = null;private Context context = null;// Bit-related controls private locationclient Mlocationclient;private Mylocationlistener mlocationlistener;private Boolean isFirstIn = true;//record latitude and longitude private double mlatitude;private double mlongtitude;//custom positioning icon Private Bitmapdescriptor miconlocation;// Direction sensor private Myorientationlistener myorientationlistener;private float mcurrentx;private locationmode mLocationMode ;//Poiprivate Poisearch mpoisearch = null; @Overrideprotected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method s Tubsuper.oncreate (savedinstancestate);//Remove Titlebarrequestwindowfeature (window.feature_no_title);// Before using the SDK components to initialize the context information, pass in applicationcontext//Note that the method is implemented before Setcontentview the method Sdkinitializer.initialize ( Getapplicationcontext ());//load Map layout file Setcontentview (r.layout.baidumap); this.context = this;//Initialize location inilocation ();// Gets the map Control reference Initview (); mbaidumap.setmylocationenabled (true); if (!mlocationclient.isstarted ())// Open positioning Mlocationclient.start ();//Open Direction Sensor Myorientationlistener.start ();} private void Inilocation () {//default is normal mode Mlocationmode = Locationmode.normal;mlocationclient = new Locationclient (this); Mlocationlistener = new Mylocationlistener ();//Registered Monitor Mlocationclient.registerlocationlistener (mLocationListener);// Set configuration locationclientoption option = new Locationclientoption (); Toast.maketext (Baidu.this, "will show The courier points within 3000 yards of you", Toast.length_long). Show ();//Set Left type Option.setcoortype ("Bd09ll"); Option.setisneedaddress (true);//Returns the location result information Option.setopengps (TRUE);//Set one second to generate a request Option.setscanspan (2000); mlocationclient.setlocoption (option);//Initialize the positioning icon Miconlocation = Bitmapdescriptorfactory.fromresource ( r.drawable.navi_map_gps_locked);//direction arrow Listener Myorientationlistener = new Myorientationlistener (context); Myorientationlistener.setonorientationlistener (New Onorientationlistener () {@Overridepublic void Onorientationchanged (float x) {mcurrentx = x;}}); private void Initview () {Mmapview = (Mapview) Findviewbyid (R.id.id_bmapview);//get to map Mbaidumap = Mmapview.getmap ();// Set the map display scale mapstatusupdate MSU = Mapstatusupdatefactory.zoomby (5.0f);//100 meters or so Mbaidumap.setmapstatus (MSU);} @Overrideprotected void OnDestroy () {//TODO auto-generated method Stubmpoisearch.destroy (); Super.ondestroy (); Mmapview.ondestroy ();} @Overrideprotected void Onresume () {//TODO auto-generated method Stubsuper.onresume (); Mmapview.onresume ();} @Overrideprotected void OnStart () {//TODO auto-generated method Stubsuper.onstart ();* * Mbaidumap.setmylocationenabled (TRUE); If * (!mlocationclient.isstarted ())//Open positioning Mlocationclient.start (); * Open Direction Sensor myorientationlistener.start (); */} @Overrideprotected void OnPause () {//TODO auto-generated method Stubsuper.onpause (); Mmapview.onpause ();} @Overrideprotected void OnStop () {//TODO auto-generated method Stubsuper.onstop ();// Stop positioning mbaidumap.setmylocationenabled (false); Mlocationclient.stop ();//Stop Direction Sensor myorientationlistener.stop ();} Button Menu @overridepublic boolean oncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.main, menu); return true;} Menu button Selection @overridepublic boolean onoptionsitemselected (MenuItem Item) {//Select User Select button via item ID switch (ITEM.GETITEMID ()) {Case r.id.id_map_commom://loading map for normal mode mbaidumap.setmaptype (baidumap.map_type_normal); Break;case R.id.id_map_site: Mbaidumap.setmaptype (baidumap.map_type_satellite); break;/* * Case r.id.id_map_location:centertomylocation (); Break */case R.id.id_map_mode_common:mlocationmode = locationmode.normal;break;/* *Case R.id.id_map_mode_following:mlocationmode = * locationmode.following; Break */case r.id.id_map_mode_compass:mlocationmode = Locationmode.compass;break;default:break;} return super.onoptionsitemselected (item);} Navigate to my Location private void Centertomylocation () {latlng latlng = new Latlng (mlatitude, mlongtitude); Mapstatusupdate MSU = MAPSTATUSUPDATEFACTORY.NEWLATLNG (LATLNG); Mbaidumap.animatemapstatus (MSU);} Private class Mylocationlistener implements Bdlocationlistener {//The callback function after successful positioning @overridepublic void Onreceivelocation ( Bdlocation location) {Mylocationdata data = new Mylocationdata.builder ()//builder mode. Direction (MCURRENTX)//.accuracy ( Location.getradius ())//.latitude (Location.getlatitude ())//.longitude (Location.getlongitude ())//.build (); Mbaidumap.setmylocationdata (data);//Set custom icon mylocationconfiguration config = new Mylocationconfiguration ( Mlocationmode, True, miconlocation); Mbaidumap.setmylocationconfigeration (config);//update latitude and longitude mlatitude = Location.getlatitude (); mlongtitude = Location.getlongItude ();//Initialize POI search Mpoisearch = poisearch.newinstance (); Mpoisearch.setongetpoisearchresultlistener (new Ongetpoisearchresultlistener () {@Overridepublic void Ongetpoiresult (poiresult result) {if (result = = Null| | Result.error = = SearchResult.ERRORNO.RESULT_NOT_FOUND) {return;} Find then show overlay if (Result.error = = SearchResult.ERRORNO.NO_ERROR) {mbaidumap.clear (); Poioverlay overlay = new Mypoioverlay (MBAIDUMAP); Mbaidumap.setonmarkerclicklistener (overlay); Overlay.setdata ( result); Overlay.addtomap (); Overlay.zoomtospan (); return;}} Click Overlay @overridepublic void Ongetpoidetailresult (poidetailresult result) {if (Result.error! = SearchResult.ERRORNO.NO _error) {Toast.maketext (baidu.this, "Sorry, no results found", Toast.length_short). Show ();} else {Toast.maketext (baidu.this, Result.getname () + ":" + result.getaddress (), Toast.length_short). Show ();/* * Toast.maketext (baidu.this, * " The courier points within 5000 yards of you will be displayed ", * Toast.length_long). Show (); */}});//Mpoisearch.setongetpoisearchresultlistener (this);/* * LATLNG latLng1 = new LATLNG (locatIon.getlatitude (), * location.getlongitude ());//Get latitude and longitude *///determine if the user first enters the map if (isfirstin) {latlng latlng = new LATLNG (locat Ion.getlatitude (), Location.getlongitude ());//Get latitude and longitude mapstatusupdate MSU = MAPSTATUSUPDATEFACTORY.NEWLATLNG (latLng); Mbaidumap.animatemapstatus (MSU); isfirstin = false; Toast.maketext (Context, Location.getaddrstr (), Toast.length_short). Show (); <span style= "color: #009900;" >mpoisearch.searchnearby ((New Poinearbysearchoption ()). Location (latlng). Keyword ("Express"). Radius (+). Pagenum (0 )); </span>}}}private class Mypoioverlay extends Poioverlay {public mypoioverlay (Baidumap baidumap) {super ( BAIDUMAP);//TODO auto-generated constructor stub}}}</span>

4, shake a shake

This is much simpler, mostly

"1" monitors the acceleration of XYZ three axes, onsensorchanged (Sensorevent event)

"2" Handler asynchronous processing event

"3" shake_action (); uses random numbers to represent events at the time of triggering


<span style= "Font-family:microsoft yahei;font-size:14px;" >package Com.leftside;import Android.annotation.suppresslint;import Android.app.activity;import Android.hardware.sensor;import Android.hardware.sensorevent;import Android.hardware.sensoreventlistener;import Android.hardware.sensormanager;import Android.media.mediaplayer;import Android.os.bundle;import Android.os.handler;import Android.os.message;import Android.os.vibrator;import Android.util.Log;import Android.view.view;import Android.widget.imageview;import Android.widget.seekbar;import Android.widget.TextView; Import Com.weimeijing.feigeshudi.r;public class Shake extends Activity {private Sensormanager sensormanager;private Vibrator Vibrator;imageview IV; MediaPlayer Mp;boolean isplay = false;private static final String TAG = "testsensoractivity";p rivate static final int SENS Or_shake = 10;private TextView tv_shake1;private TextView tv_shake2; @Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (SavedinStancestate); Setcontentview (r.layout.shake); MP = Mediaplayer.create (this, r.raw.shake); iv = (ImageView) Findviewbyid (r.id.imageview);//Get sensor Management Service Sensormanager = (Sensormanager) getsystemservice (sensor_service); vibrator = (Vibrator) Getsystemservice (Vibrator_service);/* Tv_shake1 = (TextView) Findviewbyid (R.ID.TV_SHAKE1); */tv_shake2 = (TextView) Findviewbyid (r.id.tv_shake2);} @Overrideprotected void Onresume () {super.onresume (); if (Sensormanager! = null) {// Registers the listener for the system's direction sensing Sensormanager.registerlistener (Sensoreventlistener,sensormanager.getdefaultsensor (Sensor.TYPE_ ACCELEROMETER), sensormanager.sensor_delay_normal);}} @Overrideprotected void OnPause () {super.onpause (); if (Sensormanager! = null) {// Cancel Listener Sensormanager.unregisterlistener (Sensoreventlistener);} if (isplay) {mp.stop (); Mp.release ();}} /* * Gravity Sensing monitor */private sensoreventlistener Sensoreventlistener = new Sensoreventlistener () {@Overridepublic void Onsensorc Hanged (Sensorevent event) {//The sensor information is changed when the method is executed float[] values = event.values;float x = values[0];//X-axis of the gravitational acceleration, right is positive float y = values[1];//y-axis direction of gravity, forward is positive float z = values[2];//y-axis direction of acceleration of gravity, forward is positive//according to the result of the action if (Math.Abs (x) > 14 | | Math.Abs (y) > 16 | | Math.Abs (z) >) {isplay = true;//mp.seekto (0); Vibrator.vibrate (+);//Handler Asynchronous Processing technology Message MSG = new message (); msg . What = Sensor_shake;//mp.start ();//plus this will crash? Handler.sendmessage (msg); LOG.I (TAG, "gravitational acceleration in X-Axis" + x + ", y-axis direction of gravitational acceleration" + y + "; z-axis direction of gravitational acceleration" + Z);}} @Overridepublic void onaccuracychanged (sensor sensor, int accuracy) {}}; Handler Handler = new Handler () {@Overridepublic void Handlemessage (Message msg) {super.handlemessage (msg);//mp.start () ;//Plus this will crash? Switch (msg.what) {case Sensor_shake:int i = 0;//manual delay while (true) {i++;if (i = =) break;} Shake_action (); break;default:break;}} private void Shake_action () {/* tv_shake1.setvisibility (view.visible); */int id = (int) (Math.random () * + 1); switch (i d) {case 1:tv_shake2.settext (r.string.shake1); Break;case 2:tv_shake2.settext (R.string.shake2); Break;case 3:tv_ Shake2.SetText (r.string.shake3); Break;case 4:tv_shake2.settext (R.string.shake4); Break;case 5:tv_shake2.settext ( R.STRING.SHAKE5); break;case 6:tv_shake2.settext (R.string.shake6); Break;case 7:tv_shake2.settext (R.string.shake7) ; break;case 8:tv_shake2.settext (R.string.shake8); Break;case 9:tv_shake2.settext (R.STRING.SHAKE9); Break;case 10:TV _shake2.settext (R.STRING.SHAKE10); Break;case 11:tv_shake2.settext (R.STRING.SHAKE11); Break;case 12:tv_ Shake2.settext (r.string.shake12); Break;case 13:tv_shake2.settext (R.STRING.SHAKE13); break;default:break;} Tv_shake2.setvisibility (view.visible);}};} </span>

5. Knowledge Summary

"1" slidingmenu_library the use of open source controls

"2" Baidu map

"3" sensor

Use of "4" handler



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Main interface of Palm Express (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.