How to Write a Weibo page (including inserting images, inserting emotices, inserting topics, and inserting Location) (2)

Source: Internet
Author: User

How to Write a Weibo page (including inserting images, inserting emotices, inserting topics, and inserting Location) (2)

If the write Insert location:

 

Final class LocationHelper {private LocationListener mLocationListener; private WriteBlog activity; private LocationManager mLocationManager; // default latency. Unit: Second private int timeout; private Handler uiHandler; private boolean isLocated; private LocationHolder holder; private boolean startFetching; private String defaultDraftPath; LocationHelper (WriteBlog activity) {this. activity = activity; mLocationManager = (LocationManager) activity. getSystemService (Context. LOCATION_SERVICE); uiHandler = new Handler (); timeout = 60; defaultDraftPath = activity. getFilesDir (). ge TAbsolutePath () +/draft/location. dat;} void dispose () {closeAll (); isLocated = false; startFetching = false; holder = null;} void openAllProviders () {if (startFetching | isLocated) {return;} requestProviders ();} boolean isFetching () {return startFetching;} boolean isLocatedSucess () {return (holder! = Null) & holder. isUseful ();} void closeAll () {if (mLocationListener! = Null) {mLocationManager. removeUpdates (getLocationListener (); mLocationListener = null;} private LocationListener getLocationListener () {if (mLocationListener = null) {mLocationListener = new LocationListener () {public void onLocationChanged (Location location) {final LocationHolder holder = new LocationHolder (); holder. lat = location. getLatitude (); holder. lon = location. getlongpolling (); System. out. println (==== holder. lat = + holder. lat + lon = + holder. lon); if (holder. isUseful () {isLocated = true; LocationHelper. this. holder = holder; activity. onLocatedSuccess (); closeAll (); startFetching = false ;}} public void onProviderDisabled (String provider) {} public void onProviderEnabled (String provider) {} public void onStatusChanged (String provider, int status, Bundle extras) {};} return mLocationListener;} private void requestProviders () {final List
 
  
Providers = mLocationManager. getProviders (true); boolean requestSuccess = false; if (providers. contains (LocationManager. GPS_PROVIDER) {mLocationManager. requestLocationUpdates (LocationManager. GPS_PROVIDER, 0, 0, getLocationListener (); requestSuccess = true;} if (providers. contains (LocationManager. NETWORK_PROVIDER) {mLocationManager. requestLocationUpdates (LocationManager. NETWORK_PROVIDER, 0, 0, getLocat IonListener (); requestSuccess = true;} if (requestSuccess) {activity. pgLoadingLocation. setVisibility (View. VISIBLE); startFetching = true; if (timeout> 0) {uiHandler. postDelayed (new Runnable () {public void run () {if (! IsLocated & (activity! = Null )&&! Activity. isFinishing () {closeAll (); activity. onLocatedError (); startFetching = false ;}}, timeout * 1000) ;}}} final class LocationHolder implements Serializable {private static final long serialVersionUID =-success; double lat; double lon; public boolean equals (Object o) {if (o = null) {return false;} if (o = this) {return true;} if (o. getClass () = getClass () {final LocationHolder holder = (LocationHolder) o; if (Math. abs (holder. lat-lat) <. 001) & (Math. abs (holder. lon-lon) <. 001) {return true ;}} return false;} public int hashCode () {final StringBuffer builder = new StringBuffer (); builder. append (lat ). append (lon); return builder. hashCode () ;}boolean isUseful () {return islegal (lat) & islegal (lon) ;}private boolean islegal (double pos) {if (pos> 1 .) | (pos <-1 .)) {return true;} return false ;}}
 


 

Then, we will pay attention to click events.

 

Final class FaceClickHealper {private boolean isFaceDiaplay = false; private WriteBlog activity; boolean isFaceDiaplay () {return isFaceDiaplay ;}Void onClick (View v) {activity. setEmotionViewVisibility (! IsFaceDiaplay); if (isFaceDiaplay) {activity. displayFaceImageSrc ();} else {activity. displayKeyboardImageSrc ();} activity. setInputMethodVisibility (isFaceDiaplay); changeDiaplayFlag ();} // Click EventBoolean onFinish () {if (isFaceDiaplay) {activity. displayFaceImageSrc (); activity. setEmotionViewVisibility (false); changeDiaplayFlag (); return true;} return false;} private void changeDiaplayFlag () {isFaceDiaplay =! IsFaceDiaplay;} public FaceClickHealper (WriteBlog activity) {super (); this. activity = activity ;}}

void displayFaceImageSrc() {if (ibFace != null) {ibFace.setImageResource(R.drawable.btn_insert_face);}}void displayKeyboardImageSrc() {if (ibFace != null) {ibFace.setImageResource(R.drawable.btn_insert_keyboard);}}boolean setInputMethodVisibility(boolean visibility) {if ((mInputMethodManager != null) && (etMblog != null)) {if (visibility) {mInputMethodManager.showSoftInput(etMblog, 0);}else {if (mInputMethodManager.isActive(etMblog)) {mInputMethodManager.hideSoftInputFromWindow(etMblog.getWindowToken(),InputMethodManager.HIDE_NOT_ALWAYS);}}}return false;}
void setEmotionViewVisibility(boolean visibility) { if (mEmotionView != null) { mEmotionView.setVisibility(visibility ? View.VISIBLE : View.GONE); } }

 

 


 

Related Article

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.