Sfoglia il codice sorgente

5.7.1 前台几首次进入计步界面添加动画效果

FANGLH 9 anni fa
parent
commit
55a782bc8d

+ 1 - 0
WeiChat/src/main/AndroidManifest.xml

@@ -893,6 +893,7 @@
         <activity
             android:name="com.xzjmyk.pm.newpedo.view.NewStepListActivity"
             android:label="更多历史记录" />
+        <activity android:name="com.xzjmyk.pm.newpedo.view.StepSplashActivity"/>
         <!-- 计步功能 服务-->
         <service
             android:name="com.xzjmyk.pm.newpedo.service.StepService"

+ 2 - 1
WeiChat/src/main/java/com/xzjmyk/pm/activity/ui/me/SettingActivity.java

@@ -48,6 +48,7 @@ import com.xzjmyk.pm.activity.util.PreferenceUtils;
 import com.xzjmyk.pm.activity.util.TimeUtils;
 import com.xzjmyk.pm.activity.util.ToastUtil;
 import com.xzjmyk.pm.newpedo.view.NewStepActivity;
+import com.xzjmyk.pm.newpedo.view.StepSplashActivity;
 
 import java.io.File;
 
@@ -163,7 +164,7 @@ public class SettingActivity extends ActionBackActivity implements View.OnClickL
                     PreferenceUtils.putInt(MainActivity.UU_STEP, 1);
                     PushManager.resumeWork(MyApplication.getInstance());
 //
-                    startActivity(new Intent(mContext, NewStepActivity.class));
+                    startActivity(new Intent(mContext, StepSplashActivity.class));
                 } else {
                     PushManager.stopWork(MyApplication.getInstance());
                     PreferenceUtils.putInt(MainActivity.UU_STEP, 0);

+ 12 - 1
WeiChat/src/main/java/com/xzjmyk/pm/newpedo/constant/Constant.java

@@ -9,5 +9,16 @@ package com.xzjmyk.pm.newpedo.constant;
 public class Constant {
     public static final int MSG_FROM_CLIENT = 0;
     public static final int MSG_FROM_SERVER = 1;
-
+    public static final String BASEURL = "http://news-at.zhihu.com/api/4/";
+    public static final String START = "start-image/1080*1776";
+    public static final String THEMES = "themes";
+    public static final String LATESTNEWS = "news/latest";
+    public static final String BEFORE = "news/before/";
+    public static final String THEMENEWS = "theme/";
+    public static final String CONTENT = "news/";
+    public static final int TOPIC = 131;
+    public static final String START_LOCATION = "start_location";
+    public static final String CACHE = "cache";
+    public static final int LATEST_COLUMN = Integer.MAX_VALUE;
+    public static final int BASE_COLUMN = 100000000;
 }

+ 2 - 3
WeiChat/src/main/java/com/xzjmyk/pm/newpedo/service/StepService.java

@@ -27,7 +27,7 @@ import com.xzjmyk.pm.newpedo.bean.StepEntity;
 import com.xzjmyk.pm.newpedo.constant.Constant;
 import com.xzjmyk.pm.newpedo.db.StepDataDao;
 import com.xzjmyk.pm.newpedo.utils.TimeUtil;
-import com.xzjmyk.pm.newpedo.view.NewStepActivity;
+import com.xzjmyk.pm.newpedo.view.StepSplashActivity;
 
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -102,9 +102,8 @@ public class StepService extends Service implements SensorEventListener {
         /**
          * 设置点击通知栏打开的界面,此处需要注意了,如果你的计步界面不在主界面,则需要判断app是否已经启动,
          * 再来确定跳转页面,这里面太多坑,(别问我为什么知道 - -)
-         * 总之有需要的可以和我交流
          */
-        nfIntent = new Intent(this, NewStepActivity.class);
+        nfIntent = new Intent(this, StepSplashActivity.class);
         builder.setContentIntent(PendingIntent.getActivity(this, 0, nfIntent, 0)) // 设置PendingIntent
                 .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.uuu)) // 设置下拉列表中的图标(大图标)
                 .setContentTitle("UU运动正在后台运行") // 设置下拉列表里的标题

+ 36 - 0
WeiChat/src/main/java/com/xzjmyk/pm/newpedo/utils/StepHttpUtils.java

@@ -0,0 +1,36 @@
+package com.xzjmyk.pm.newpedo.utils;
+
+import android.content.Context;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+
+import com.loopj.android.http.AsyncHttpClient;
+import com.loopj.android.http.ResponseHandlerInterface;
+import com.xzjmyk.pm.newpedo.constant.Constant;
+/**
+ *Created by FANGlh on 2017/4/24.
+ * function:
+ */
+public class StepHttpUtils {
+    private static AsyncHttpClient client = new AsyncHttpClient();
+
+    public static void get(String url, ResponseHandlerInterface responseHandler) {
+        client.get(Constant.BASEURL + url, responseHandler);
+    }
+
+    public static void getImage(String url, ResponseHandlerInterface responseHandler) {
+        client.get(url, responseHandler);
+    }
+
+    public static boolean isNetworkConnected(Context context) {
+        if (context != null) {
+            ConnectivityManager mConnectivityManager = (ConnectivityManager) context
+                    .getSystemService(Context.CONNECTIVITY_SERVICE);
+            NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
+            if (mNetworkInfo != null) {
+                return mNetworkInfo.isAvailable();
+            }
+        }
+        return false;
+    }
+}

+ 143 - 0
WeiChat/src/main/java/com/xzjmyk/pm/newpedo/view/StepSplashActivity.java

@@ -0,0 +1,143 @@
+package com.xzjmyk.pm.newpedo.view;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.graphics.BitmapFactory;
+import android.os.Bundle;
+import android.os.Handler;
+import android.view.Window;
+import android.view.WindowManager;
+import android.view.animation.Animation;
+import android.view.animation.ScaleAnimation;
+import android.widget.ImageView;
+import android.widget.Toast;
+
+import com.loopj.android.http.AsyncHttpResponseHandler;
+import com.loopj.android.http.BinaryHttpResponseHandler;
+import com.xzjmyk.pm.activity.R;
+import com.xzjmyk.pm.newpedo.constant.Constant;
+import com.xzjmyk.pm.newpedo.utils.StepHttpUtils;
+
+import org.apache.http.Header;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+/**
+ *Created by FANGlh on 2017/4/24.
+ * function:
+ */
+public class StepSplashActivity extends Activity {
+    private ImageView iv_start;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        requestWindowFeature(Window.FEATURE_NO_TITLE);
+        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
+        setContentView(R.layout.step_splash);
+        iv_start = (ImageView) findViewById(R.id.iv_start);
+        initImage();
+
+        new Handler().postDelayed(new Runnable() {
+                        @Override
+                        public void run() {
+                            startActivity();
+                        }
+                    }, 3000);
+
+    }
+
+    private void initImage() {
+        File dir = getFilesDir();
+        final File imgFile = new File(dir, "start.jpg");
+        if (imgFile.exists()) {
+            iv_start.setImageBitmap(BitmapFactory.decodeFile(imgFile.getAbsolutePath()));
+        } else {
+            iv_start.setImageResource(R.drawable.start_splash1);
+        }
+
+        final ScaleAnimation scaleAnim = new ScaleAnimation(1.0f, 1.2f, 1.0f, 1.2f,
+                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
+                0.5f);
+        scaleAnim.setFillAfter(true);
+        scaleAnim.setDuration(3000);
+        scaleAnim.setAnimationListener(new Animation.AnimationListener() {
+            @Override
+            public void onAnimationStart(Animation animation) {
+
+            }
+
+            @Override
+            public void onAnimationEnd(Animation animation) {
+                if (StepHttpUtils.isNetworkConnected(StepSplashActivity.this)) {
+                    StepHttpUtils.get(Constant.START, new AsyncHttpResponseHandler() {
+                        @Override
+                        public void onSuccess(int i, Header[] headers, byte[] bytes) {
+                            try {
+                                JSONObject jsonObject = new JSONObject(new String(bytes));
+                                String url = jsonObject.getString("img");
+                                StepHttpUtils.getImage(url, new BinaryHttpResponseHandler() {
+                                    @Override
+                                    public void onSuccess(int i, Header[] headers, byte[] bytes) {
+                                        saveImage(imgFile, bytes);
+                                        startActivity();
+                                    }
+
+                                    @Override
+                                    public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
+                                        startActivity();
+                                    }
+                                });
+
+                            } catch (JSONException e) {
+                                e.printStackTrace();
+                            }
+                        }
+
+                        @Override
+                        public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
+                            startActivity();
+                        }
+                    });
+                } else {
+                    Toast.makeText(StepSplashActivity.this, "没有网络连接!", Toast.LENGTH_LONG).show();
+                    startActivity();
+                }
+            }
+
+            @Override
+            public void onAnimationRepeat(Animation animation) {
+
+            }
+        });
+        iv_start.startAnimation(scaleAnim);
+
+    }
+
+    private void startActivity() {
+        Intent intent = new Intent(StepSplashActivity.this, NewStepActivity.class);
+        startActivity(intent);
+        overridePendingTransition(android.R.anim.fade_in,
+                android.R.anim.fade_out);
+        finish();
+    }
+
+    public void saveImage(File file, byte[] bytes) {
+        try {
+            if (file.exists()) {
+                file.delete();
+            }
+            FileOutputStream fos = new FileOutputStream(file);
+            fos.write(bytes);
+            fos.flush();
+            fos.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+    }
+}

BIN
WeiChat/src/main/res/drawable-xxhdpi/start_splash1.jpg


BIN
WeiChat/src/main/res/drawable-xxhdpi/step_start.jpg


+ 14 - 0
WeiChat/src/main/res/layout/step_splash.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:layout_gravity="center_vertical">
+
+    <ImageView
+        android:id="@+id/iv_start"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:adjustViewBounds="true"
+        android:scaleType="fitXY" />
+
+</RelativeLayout>