渐显启动界面.md
16lz
2021-01-26
package com.leigo.textswitcherdemo;import android.app.Activity;import android.content.Intent;import android.content.SharedPreferences;import android.graphics.Bitmap;import android.graphics.BitmapFactory;import android.os.Bundle;import android.preference.PreferenceManager;import android.view.View;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.widget.ImageView;import android.widget.TextView;import com.loopj.android.http.AsyncHttpClient;import com.loopj.android.http.JsonHttpResponseHandler;import com.nostra13.universalimageloader.core.ImageLoader;import com.nostra13.universalimageloader.core.assist.FailReason;import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;import org.apache.http.Header;import org.json.JSONException;import org.json.JSONObject;/** * Created by Administrator on 2015/3/16. */public class SplashActivity extends Activity { public Animation splashAnim; ImageView mImageView; TextView mText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_splash); mImageView = (ImageView) findViewById(R.id.splash); mText = (TextView) findViewById(R.id.text); splashAnim = AnimationUtils.loadAnimation(this, R.anim.splash); splashAnim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { Intent intent = new Intent(SplashActivity.this, MainActivity.class); startActivity(intent); finish(); } @Override public void onAnimationRepeat(Animation animation) { } }); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); if (!sp.contains("preferences_splash_text")) { mText.setText(R.string.splash_text); mImageView.setImageResource(R.drawable.splash); mImageView.startAnimation(splashAnim); AsyncHttpClient client = new AsyncHttpClient(); client.get("http://news-at.zhihu.com/api/4/start-image/1080*1776", new JsonHttpResponseHandler() { @Override public void onStart() { super.onStart(); } @Override public void onSuccess(int statusCode, Header[] headers, JSONObject response) { super.onSuccess(statusCode, headers, response); try { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(SplashActivity.this); SharedPreferences.Editor editor = sp.edit(); editor.putString("preferences_splash_text", response.getString("text")); editor.putString("preferences_splash_image", response.getString("img")); editor.apply(); ImageLoader.getInstance().loadImage(response.getString("img"), new SimpleImageLoadingListener() { @Override public void onLoadingStarted(String imageUri, View view) { } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { } @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { FileUtils.storeImage(SplashActivity.this, loadedImage); } @Override public void onLoadingCancelled(String imageUri, View view) { } }); } catch (JSONException e) { e.printStackTrace(); } } @Override public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) { super.onFailure(statusCode, headers, responseString, throwable); } @Override public void onRetry(int retryNo) { super.onRetry(retryNo); } }); } else { String text = sp.getString("preferences_splash_text", getString(R.string.splash_text)); mText.setText(text); Bitmap bitmap = BitmapFactory.decodeFile(FileUtils.getOutputMediaFile(this).getAbsolutePath()); mImageView.setImageBitmap(bitmap); mImageView.startAnimation(splashAnim); } }}
<?xml version="1.0" encoding="utf-8"?><RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <ImageView android:id="@+id/splash" android:layout_width="match_parent" android:layout_height="match_parent" android:scaleType="centerCrop" /> <ImageView android:layout_width="match_parent" android:layout_height="200.0dip" android:src="@drawable/mask" android:layout_alignParentBottom="true" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="50.0dip" android:src="@drawable/splash_logo" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" /> <TextView android:textSize="@dimen/text_size_12" android:textColor="#ffffffff" android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10.0dip" android:text="@string/splash_text" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:alpha="0.5" /></RelativeLayout>
<?xml version="1.0" encoding="utf-8"?><set android:shareInterpolator="false" android:zAdjustment="top" android:fillBefore="true" android:fillAfter="true" android:fillEnabled="true" xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:duration="2500" android:pivotX="50.0%p" android:pivotY="50.0%p" android:fromXScale="1.0" android:toXScale="1.1" android:fromYScale="1.0" android:toYScale="1.1" /> <alpha android:duration="500" android:startOffset="2000" android:fromAlpha="1.0" android:toAlpha="0.0" /></set>
package com.leigo.textswitcherdemo;import android.content.Context;import android.graphics.Bitmap;import android.os.Environment;import android.util.Log;import java.io.File;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;/** * Created by Administrator on 2015/3/19. */public class FileUtils { private static final String TAG = FileUtils.class.getSimpleName(); public static void storeImage(Context context, Bitmap image) { File pictureFile = getOutputMediaFile(context); if (pictureFile == null) { Log.d(TAG, "Error creating media file, check storage permissions: ");// e.getMessage()); return; } try { FileOutputStream fos = new FileOutputStream(pictureFile); image.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { Log.d(TAG, "File not found: " + e.getMessage()); } catch (IOException e) { Log.d(TAG, "Error accessing file: " + e.getMessage()); } } /** * Create a File for saving an image or video */ public static File getOutputMediaFile(Context context) { // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. File mediaStorageDir = new File(Environment.getExternalStorageDirectory() + "/Android/data/" + context.getApplicationInfo().packageName + "/files/" + "splash"); // This location works best if you want the created images to be shared // between applications and persist after your app has been uninstalled. // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { return null; } } // Create a media file name File mediaFile = new File(mediaStorageDir.getPath() + File.separator + "splash.jpg"); return mediaFile; }}
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer