5.WebService
package com.recycler.zx.zxrecyclerview.volleyAndAsyncAndWebservice;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import com.recycler.zx.zxrecyclerview.R;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import java.lang.ref.WeakReference;
import butterknife.Bind;
import butterknife.ButterKnife;
public class WebServiceActivity extends AppCompatActivity {
@Bind(R.id.button4)
Button button4;
private MyHandler myHandler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_web_service);
ButterKnife.bind(this);
}
public void webServiceClick(View v) {
myHandler = new MyHandler(this);
new Thread(new Runnable() {
@Override
public void run() {
getTelephoneInfo("13888888888");
}
}).start();
}
private static class MyHandler extends Handler {
private WeakReference<WebServiceActivity> mWeakReference;
private WebServiceActivity mActivity;
public MyHandler(WebServiceActivity activity) {
mWeakReference = new WeakReference<WebServiceActivity>(activity);
mActivity = mWeakReference.get();
}
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (mActivity != null) {
String result = (String) msg.obj;
mActivity.button4.setText(result);
}
}
}
public void getTelephoneInfo(String phone_number) {
//命名空间
String nameSpace = "http://WebXml.com.cn/";
//调用的方法名称
String methodName = "getMobileCodeInfo";
// webservice的网址
String URL = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx";
//命名空间+方法
String soapAction = "http://WebXml.com.cn/getMobileCodeInfo";
// 指定WebService的命名空间和调用的方法名
SoapObject rpc = new SoapObject(nameSpace, methodName);
// 设置需调用WebService接口需要传入的两个参数mobileCode、userId
rpc.addProperty("mobileCode", phone_number);
rpc.addProperty("userId", "");
// 生成调用WebService方法的SOAP请求信息,并指定SOAP的版本
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.bodyOut = rpc;
// 设置是否调用的是dotNet开发的WebService
envelope.dotNet = true;
// 等价于
/* envelope.bodyOut = rpc;
envelope.setOutputSoapObject(rpc);*/
HttpTransportSE transport = new HttpTransportSE(URL);
try {
// 调用WebService
transport.call(soapAction, envelope);
} catch (Exception e) {
e.printStackTrace();
}
// 获取返回的数据
SoapObject object = (SoapObject) envelope.bodyIn;
// 获取返回的结果
String result = object.getProperty(0).toString();
Message msg = myHandler.obtainMessage();
msg.obj = result;
myHandler.sendMessage(msg);
}
}
6.WebView与js交互
private void initWebView() {
WebSettings settings = wvList.getSettings();
settings.setJavaScriptEnabled(true);
settings.setBuiltInZoomControls(true);
wvList.requestFocus();
wvList.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
//设置点击链接在webview中显示
wvList.setWebViewClient(new WebViewClient());
wvList.setWebChromeClient(new WebChromeClient());
//wvList.loadUrl("http://www.baidu.com/");
myHandler = new MyHandler(this);
wvList.addJavascriptInterface(new myObj(),"myweb");
wvList.loadUrl("file:///android_asset/html/index.html");
}
public class myObj{
@JavascriptInterface
public void toWeb(){
myHandler.post(new Runnable() {
@Override
public void run() {
wvList.loadUrl("javascript:myfun()");
}
});
}
}
<html lang="en">
<head>
<title>Document</title>
<script language="JavaScript">
function myfun(){
document.getElementById("imgId").src="b.jpg";
}
</script>
</head>
<body>
<a onclick="window.myweb.toWeb()">
<img src="a.jpg" id="imgId" />
</a>
</body>
</html>
7.属性动画和视图动画(tween(补间动画),frame(帧动画))
package com.recycler.zx.zxrecyclerview.tweenAndframe;
import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.BounceInterpolator;
import android.widget.ImageView;
import android.widget.Toast;
import com.recycler.zx.zxrecyclerview.R;
import butterknife.Bind;
import butterknife.ButterKnife;
//android 中的动画注意:视图动画:animation(动画),属性动画:animator(动画绘制者)
public class AnimationsActivity extends AppCompatActivity {
@Bind(R.id.iv_tween)
ImageView ivTween;
@Bind(R.id.iv_frame)
ImageView ivFrame;
@Bind(R.id.iv_attribute)
ImageView ivAttribute;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animations);
ButterKnife.bind(this);
}
//**************************************************************************************************视图动画
public void tween(View v) {
//1.xml中创建动画 alpha_anim.xml//渐渐消失
Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate_anim);
ivTween.startAnimation(animation);
//2.直接在程序中创建动画
// Animation animation2 = new AlphaAnimation(0.0f,1.0f);
//ivAnim.startAnimation(animation2);
}
public void frame(View v) {
AnimationDrawable animation = (AnimationDrawable) ivFrame.getDrawable();
animation.start();
}
//**************************************************************************************************属性动画
//属性动画有代码实现和xml实现2中
//属性动画,,用的最多,下面先代码实现再xml实现(xml中属性动画在animator文件夹中,视图动画是在anim文件夹中)
public void attribute(View v) {
ObjectAnimator
.ofFloat(ivAttribute, "rotationx", 0.0f, 360.0f)
.setDuration(500).start();
}
public void propertyValuesHolder(View v){
//ObjectAnimator
/*PropertyValuesHolder phx = PropertyValuesHolder.ofFloat("alpha",1f,0f,1f);
PropertyValuesHolder phy = PropertyValuesHolder.ofFloat("scaleX",1f,0,1f);
PropertyValuesHolder phz = PropertyValuesHolder.ofFloat("scaleY",1f,0,1f);
ObjectAnimator.ofPropertyValuesHolder(v,phx,phy,phz).setDuration(5000).start();*/
//ValueAnimator
final View view = v;
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
//定义一个动画
ValueAnimator anim = ValueAnimator.ofFloat(v.getX(),dm.widthPixels+v.getWidth(),v.getX()).setDuration(500);
//监听动画的每个动作
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener(){
@Override
public void onAnimationUpdate(ValueAnimator animation) {
view.setTranslationX((Float) animation.getAnimatedValue());
}
});
anim.start();
}
public void animListener(final View v){
//1f:开始,0f:结束
ObjectAnimator anim = ObjectAnimator.ofFloat(v,"alpha",1f,0f).setDuration(500);
anim.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
//动画开始
}
@Override
public void onAnimationEnd(Animator animation) {
//动画结束
ViewGroup vg = (ViewGroup) v.getParent();
if(vg != null) {
vg.removeView(v);
Toast.makeText(AnimationsActivity.this,"已删除view",Toast.LENGTH_SHORT).show();
}
}
@Override
public void onAnimationCancel(Animator animation) {
//取消动画
}
@Override
public void onAnimationRepeat(Animator animation) {
//重复播放
}
});
//上面的方法比较麻烦,如果你只想使用onAnimationEnd(其中一个方法就不方便)
// 可以直接使用监听适配器,实现单个方法,比较灵活
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
//动画结束
ViewGroup vg = (ViewGroup) v.getParent();
if(vg != null) {
vg.removeView(v);
Toast.makeText(AnimationsActivity.this,"已删除view",Toast.LENGTH_SHORT).show();
}
}
});
anim.start();
}
//排序播放动画,不是同时播发,(比如,先播发a动画,再播放b动画)
public void animSet(View v){
ObjectAnimator oax = ObjectAnimator.ofFloat(v,"translationX",0f,200f);
ObjectAnimator oay = ObjectAnimator.ofFloat(v,"translationY",0f,200f);
ObjectAnimator oarotation = ObjectAnimator.ofFloat(v,"rotation",0f,360.0f);
AnimatorSet set = new AnimatorSet();
set.setDuration(2000);
//排序设置
//set.playTogether(oax,oay,oarotation);//3个动画同时执行
//set.playSequentially(oay,oax,oarotation);//按参数顺序执行
//set.setStartDelay(300);//延迟执行
//oax,oay同时执行,之后执行oarotation
set.play(oax).with(oay);
set.play(oarotation).after(oay);
set.start();
//注意:不能set.play(oax).with(oay).after().before()连接太长
}
/* 插值器,就是告诉Android,播放动画时
是从快到慢还是从慢到快,从左到右的旋转还是其它的方式的动画,
类型如下面的八种,跟scale.xml或alpha.xml中使用的插值器一样的,只是写的形式不一样而已
所有的插值器都实现Interpolator接口中的 getInterpolation(float input)方法,
注意一点,插值器不能同时set多个,不然最前面的会被覆盖,即:无效果..
/* new AccelerateDecelerateInterpolator();
* new AccelerateInterpolator();
* new CycleInterpolator(1.0f);
* new DecelerateInterpolator();
* new AnticipateInterpolator();
* new AnticipateOvershootInterpolator();
* new BounceInterpolator();
* new OvershootInterpolator();
* new LinearInterpolator();
### 最后我想说
**为什么很多程序员做不了架构师?**
1、良好健康的职业规划很重要,但大多数人都忽略了
2、学习的习惯很重要,持之以恒才是正解。
3、编程思维没能提升一个台阶,局限在了编码,业务,没考虑过选型、扩展
4、身边没有好的架构师引导、培养。所处的圈子对程序员的成长影响巨大。
金九银十面试季,跳槽季,整理面试题已经成了我多年的习惯!**在这里我和身边一些朋友特意整理了一份快速进阶为Android高级工程师的系统且全面的学习资料。涵盖了Android初级——Android高级架构师进阶必备的一些学习技能。**
附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题(含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)
![](https://img-blog.csdnimg.cn/img_convert/c7701ac987d2536701bd38748e48c4bb.webp?x-oss-process=image/format,png)
**里面包含不同方向的自学编程路线、面试题集合/面经、及系列技术文章等,资源持续更新中…**
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化学习资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618156601)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
、学习的习惯很重要,持之以恒才是正解。
3、编程思维没能提升一个台阶,局限在了编码,业务,没考虑过选型、扩展
4、身边没有好的架构师引导、培养。所处的圈子对程序员的成长影响巨大。
金九银十面试季,跳槽季,整理面试题已经成了我多年的习惯!**在这里我和身边一些朋友特意整理了一份快速进阶为Android高级工程师的系统且全面的学习资料。涵盖了Android初级——Android高级架构师进阶必备的一些学习技能。**
附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题(含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)
[外链图片转存中...(img-V77WXAhO-1714399852123)]
**里面包含不同方向的自学编程路线、面试题集合/面经、及系列技术文章等,资源持续更新中…**
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化学习资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618156601)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**