Android Open Source - YahooWeather Shake2 Share






From Project

Back to project page YahooWeather.

License

The source code is released under:

GNU General Public License

If you think the Android project YahooWeather listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * ????:http://www.ShareSDK.cn/*from w  w  w .j  av  a2s  .c o  m*/
 * ?????QQ: 4006852216
 * ????:ShareSDK   ??????????????????????????????????????????????????????????????????????????????24??????????
 *
 * Copyright (c) 2013? ShareSDK.cn. All rights reserved.
 */

package cn.sharesdk.onekeyshare;

import static cn.sharesdk.framework.utils.R.*;
import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.util.FloatMath;
import android.view.Window;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.ImageView.ScaleType;
import cn.sharesdk.framework.FakeActivity;

/** ????????????? */
public class Shake2Share extends FakeActivity implements SensorEventListener {
  // ???????
  private static final int UPDATE_INTERVAL = 100;
  // ???????????????????????????
  private static final int SHAKE_THRESHOLD = 1500;

  private OnShakeListener listener;
  private SensorManager mSensorManager;
  private long mLastUpdateTime;
  private float mLastX;
  private float mLastY;
  private float mLastZ;
  private boolean shaken;

  public void setOnShakeListener(OnShakeListener listener) {
    this.listener = listener;
  }

  public void setActivity(Activity activity) {
    super.setActivity(activity);
    int resId = getBitmapRes(activity, "ssdk_oks_shake_to_share_back");
    if (resId > 0) {
      activity.setTheme(android.R.style.Theme_Dialog);
      activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
      Window win = activity.getWindow();
      win.setBackgroundDrawableResource(resId);
    }
  }

  public void onCreate() {
    startSensor();

    int resId = getBitmapRes(activity, "ssdk_oks_yaoyiyao");
    if (resId > 0) {
      ImageView iv = new ImageView(activity);
      iv.setScaleType(ScaleType.CENTER_INSIDE);
      iv.setImageResource(resId);
      activity.setContentView(iv);
    }

    resId = getStringRes(activity, "shake2share");
    if (resId > 0) {
      Toast.makeText(activity, resId, Toast.LENGTH_SHORT).show();
    }
  }

  private void startSensor() {
    mSensorManager = (SensorManager) activity.getSystemService(Context.SENSOR_SERVICE);
    if (mSensorManager == null) {
      throw new UnsupportedOperationException();
    }
    Sensor sensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    if (sensor == null) {
      throw new UnsupportedOperationException();
    }
    boolean success = mSensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_GAME);
    if (!success) {
      throw new UnsupportedOperationException();
    }
  }

  public void onDestroy() {
    stopSensor();
  }

  private void stopSensor() {
    if (mSensorManager != null) {
      mSensorManager.unregisterListener(this);
      mSensorManager = null;
    }
  }

  public void onSensorChanged(SensorEvent event) {
    long currentTime = System.currentTimeMillis();
    long diffTime = currentTime - mLastUpdateTime;
    if (diffTime > UPDATE_INTERVAL) {
      if(mLastUpdateTime != 0) {
        float x = event.values[0];
        float y = event.values[1];
        float z = event.values[2];
        float deltaX = x - mLastX;
        float deltaY = y - mLastY;
        float deltaZ = z - mLastZ;
        float delta = FloatMath.sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ) / diffTime * 10000;
        if (delta > SHAKE_THRESHOLD) {
          if (!shaken) {
            shaken = true;
            finish();
          }

          if (listener != null) {
            listener.onShake();
          }
        }
        mLastX = x;
        mLastY = y;
        mLastZ = z;
      }
      mLastUpdateTime = currentTime;
    }
  }

  public void onAccuracyChanged(Sensor sensor, int accuracy) {

  }

  public static interface OnShakeListener {
    public void onShake();
  }

}




Java Source Code List

cn.sharesdk.demo.wxapi.WXEntryActivity.java
cn.sharesdk.onekeyshare.CustomerLogo.java
cn.sharesdk.onekeyshare.EditPage.java
cn.sharesdk.onekeyshare.FollowList.java
cn.sharesdk.onekeyshare.OnekeyShare.java
cn.sharesdk.onekeyshare.PicViewer.java
cn.sharesdk.onekeyshare.PlatformGridView.java
cn.sharesdk.onekeyshare.Shake2Share.java
cn.sharesdk.onekeyshare.ShareContentCustomizeCallback.java
cn.sharesdk.onekeyshare.ShareCore.java
com.imlongluo.weather.MainActivity.java
com.imlongluo.weather.WeatherApplication.java
com.imlongluo.weather.apis.AsciiUtils.java
com.imlongluo.weather.apis.ImageUtils.java
com.imlongluo.weather.apis.NetworkUtils.java
com.imlongluo.weather.apis.UserLocationUtils.java
com.imlongluo.weather.apis.WOEIDInfo.java
com.imlongluo.weather.apis.WOEIDUtils.java
com.imlongluo.weather.apis.WeatherInfo.java
com.imlongluo.weather.apis.YahooWeatherConsts.java
com.imlongluo.weather.apis.YahooWeatherExceptionListener.java
com.imlongluo.weather.apis.YahooWeatherInfoListener.java
com.imlongluo.weather.apis.YahooWeatherLog.java
com.imlongluo.weather.apis.YahooWeather.java
com.imlongluo.weather.lbs.LocationGetter.java
com.imlongluo.weather.lbs.LocationManagerActivity.java
com.imlongluo.weather.settings.SettingsActivity.java
com.imlongluo.weather.share.ShareActivity.java
com.imlongluo.weather.utils.Constants.java
com.imlongluo.weather.utils.Utils.java