赞
踩
public class App extends Application { @Override public void onCreate() { super.onCreate(); UMConfigure.init(this, "5a12384aa40fa3551f0001d1" , "umeng", UMConfigure.DEVICE_TYPE_PHONE, "");//58edcfeb310c93091c000be2 5965ee00734be40b580001a0 UMConfigure.setLogEnabled(true); PlatformConfig.setWeixin("wxdc1e388c3822c80b", "3baf1193c85774b3fd9d18447d76cab0"); //豆瓣RENREN平台目前只能在服务器端配置 PlatformConfig.setSinaWeibo("3921700954", "04b48b094faeb16683c32669824ebdad", "http://sns.whalecloud.com"); PlatformConfig.setYixin("yxc0614e80c9304c11b0391514d09f13bf"); PlatformConfig.setQQZone("100424468", "c7394704798a158208a74ab60104f0ba"); PlatformConfig.setTwitter("3aIN7fuF685MuZ7jtXkQxalyi", "MK6FEYG63eWcpDFgRYw4w9puJhzDl0tyuqWjZ3M7XJuuG7mMbO"); PlatformConfig.setAlipay("2015111700822536"); PlatformConfig.setLaiwang("laiwangd497e70d4", "d497e70d4c3e4efeab1381476bac4c5e"); PlatformConfig.setPinterest("1439206"); PlatformConfig.setKakao("e4f60e065048eb031e235c806b31c70f"); PlatformConfig.setDing("dingoalmlnohc0wggfedpk"); PlatformConfig.setVKontakte("5764965", "5My6SNliAaLxEm3Lyd9J"); PlatformConfig.setDropbox("oz8v5apet3arcdy", "h7p2pjbzkkxt02a"); } }
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity">
-
- <ImageView
- android:id="@+id/img_pic"
- android:layout_width="100dp"
- android:layout_height="100dp"
- android:layout_alignParentTop="true"
- android:layout_centerHorizontal="true"
- android:layout_marginTop="66dp"
- android:src="@drawable/a" />
-
- <EditText
- android:id="@+id/edit_mobile"
- android:layout_width="200dp"
- android:layout_height="48dp"
- android:layout_alignParentTop="true"
- android:layout_centerHorizontal="true"
- android:layout_marginTop="220dp"
- android:hint="请输入登录手机号"
- android:textSize="18sp" />
-
- <EditText
- android:id="@+id/edit_password"
- android:layout_width="200dp"
- android:layout_height="48dp"
- android:layout_centerInParent="true"
- android:hint="请输入密码"
- android:password="true"
- android:textSize="18sp" />
-
- <Button
- android:id="@+id/btn_login"
- android:layout_width="138dp"
- android:layout_height="50dp"
- android:layout_alignParentBottom="true"
- android:layout_centerHorizontal="true"
- android:layout_marginBottom="195dp"
- android:background="#f40c04"
- android:text="登录"
- android:textSize="25sp" />
-
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="37dp"
- android:layout_alignParentBottom="true"
- android:layout_centerHorizontal="true"
- android:layout_marginBottom="128dp"
- android:text="--第三方登录--"
- android:textColor="#f1e505"
- android:id="@+id/txt"
- android:textSize="27sp" />
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
- android:orientation="horizontal">
- <ImageView
- android:id="@+id/btn_qq"
- android:layout_width="50dp"
- android:layout_height="50dp"
- android:layout_alignParentBottom="true"
- android:layout_marginBottom="47dp"
- android:src="@drawable/umeng_socialize_qq"
- android:layout_weight="1"/>
-
- <ImageView
- android:id="@+id/login_wx"
- android:layout_width="50dp"
- android:layout_height="50dp"
- android:layout_weight="1"
- android:layout_alignParentBottom="true"
- android:layout_marginBottom="47dp"
- android:src="@drawable/umeng_socialize_wechat" />
-
- </LinearLayout>
-
- </RelativeLayout>
-
-
- Activity
- import android.Manifest;
- import android.content.Intent;
- import android.os.Build;
- import android.os.Bundle;
- import android.support.v4.app.ActivityCompat;
- import android.support.v7.app.AppCompatActivity;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.ImageView;
- import android.widget.Toast;
-
- import com.umeng.socialize.UMAuthListener;
- import com.umeng.socialize.UMShareAPI;
- import com.umeng.socialize.bean.SHARE_MEDIA;
- import com.umeng.soexample.MainActivity;
- import com.umeng.soexample.R;
- import com.umeng.soexample.mvp.presenter.LoginPresenter;
- import com.umeng.soexample.mvp.view.LoginView;
-
- import java.util.Map;
-
- public class LoginActivity extends AppCompatActivity implements LoginView {
-
- private EditText mEditMobile;
- private EditText mEditPassword;
- private Button mBtnLogin;
- private ImageView mBtnQq;
- private ImageView mLoginWx;
- private LoginPresenter loginPresenter;
- private UMAuthListener authListener;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- initView();
- initViewListener();
- initAuthority();
- loginPresenter = new LoginPresenter(this);
- initListener();
- }
-
- private void initListener() {
- authListener = new UMAuthListener() {
- /**
- * @desc 授权开始的回调
- * @param platform 平台名称
- */
- @Override
- public void onStart(SHARE_MEDIA platform) {
-
- }
-
- /**
- * @desc 授权成功的回调
- * @param platform 平台名称
- * @param action 行为序号,开发者用不上
- * @param data 用户资料返回
- */
- @Override
- public void onComplete(SHARE_MEDIA platform, int action, Map<String, String> data) {
- Intent intent = new Intent(LoginActivity.this, MainActivity.class);
- intent.putExtra("name", data.get("name"));
- intent.putExtra("pic", data.get("iconurl"));
- startActivity(intent);
- finish();
- }
-
- /**
- * @desc 授权失败的回调
- * @param platform 平台名称
- * @param action 行为序号,开发者用不上
- * @param t 错误原因
- */
- @Override
- public void onError(SHARE_MEDIA platform, int action, Throwable t) {
-
- Toast.makeText(LoginActivity.this, "失败:" + t.getMessage(), Toast.LENGTH_LONG).show();
- }
-
- /**
- * @desc 授权取消的回调
- * @param platform 平台名称
- * @param action 行为序号,开发者用不上
- */
- @Override
- public void onCancel(SHARE_MEDIA platform, int action) {
- Toast.makeText(LoginActivity.this, "取消了", Toast.LENGTH_LONG).show();
- }
- };
- }
-
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
- }
-
- //动态权限
- private void initAuthority() {
- if (Build.VERSION.SDK_INT >= 23) {
- String[] mPermissionList = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
- Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.CALL_PHONE, Manifest.permission.READ_LOGS,
- Manifest.permission.READ_PHONE_STATE, Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.SET_DEBUG_APP,
- Manifest.permission.SYSTEM_ALERT_WINDOW, Manifest.permission.GET_ACCOUNTS, Manifest.permission.WRITE_APN_SETTINGS};
- ActivityCompat.requestPermissions(this, mPermissionList, 123);
- }
- }
-
- private void initViewListener() {
- mBtnLogin.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- String mobile = mEditMobile.getText().toString().trim();
- String password = mEditPassword.getText().toString().trim();
- loginPresenter.login(mobile, password);
- }
- });
- mBtnQq.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- UMShareAPI.get(LoginActivity.this).getPlatformInfo(LoginActivity.this, SHARE_MEDIA.QQ, authListener);
- }
- });
- mLoginWx.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- UMShareAPI.get(LoginActivity.this).getPlatformInfo(LoginActivity.this, SHARE_MEDIA.WEIXIN, authListener);
- }
- });
- }
-
- private void initView() {
- mEditMobile = (EditText) findViewById(R.id.edit_mobile);
- mEditPassword = (EditText) findViewById(R.id.edit_password);
- mBtnLogin = (Button) findViewById(R.id.btn_login);
- mBtnQq = (ImageView) findViewById(R.id.btn_qq);
- mLoginWx = (ImageView) findViewById(R.id.login_wx);
- }
-
- @Override
- public void onSuccess(String result) {
- Intent intent = new Intent(this, MainActivity.class);
- startActivity(intent);
- finish();
- }
-
- @Override
- public void onFailer(String msg) {
- Toast.makeText(LoginActivity.this, msg, Toast.LENGTH_SHORT).show();
- }
-
- @Override
- public void onRequestPermissionsResult(int requestCode,
- String permissions[], int[] grantResults) {
-
- }
- }
import java.io.Serializable; public class LoginBean implements Serializable { private String msg; private String code; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } }
public interface LoginView {
//成功
void onSuccess(String result);
//失败
void onFailer(String msg);
}
import com.google.gson.Gson; import com.umeng.soexample.bean.LoginBean; import com.umeng.soexample.mvp.presenter.LoginCallback; import com.umeng.soexample.util.OkHttpHelper; import com.umeng.soexample.util.OkHttpHelperListener; public class LoginModel { public void login(String mobile, String password, final LoginCallback loginCallback){ final String url = "http://www.zhaoapi.cn/user/login?mobile="+mobile+"&password="+password; new OkHttpHelper().get( url ).setListener(new OkHttpHelperListener() { @Override public void succeed(String data) { Gson gson = new Gson(); LoginBean loginBean = gson.fromJson( data, LoginBean.class ); if (loginBean.getCode().equals( "0" )) { loginCallback.onLoginSuccess( loginBean.getMsg() ); }else { loginCallback.onLoginFailer( loginBean.getMsg() ); } } @Override public void failure(String error) { } } ); } }
import com.umeng.soexample.mvp.model.LoginModel; import com.umeng.soexample.mvp.view.LoginView; public class LoginPresenter { public LoginModel loginModel; public LoginView loginView; public LoginPresenter(LoginView loginView){ this.loginView = loginView; loginModel = new LoginModel(); } public void login(String mobile,String password){ loginModel.login( mobile, password, new LoginCallback() { @Override public void onLoginSuccess(String result) { loginView.onSuccess( result ); } @Override public void onLoginFailer(String msg) { loginView.onFailer( msg ); } } ); } }
- public interface LoginCallback {
- //登录成功
- void onLoginSuccess(String result);
- //登录失败
- void onLoginFailer(String msg);
- }
- //接口
- public interface OkHttpHelperListener {
-
- void succeed(String data);
- void failure(String error);
- }
//工具类 import android.annotation.SuppressLint; import android.os.Handler; import android.os.Message; import android.util.Log; import java.io.IOException; import okhttp3.Call; import okhttp3.Callback; import okhttp3.HttpUrl; import okhttp3.Interceptor; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; public class OkHttpHelper { OkHttpHelperListener listener; public void setListener(OkHttpHelperListener listener) { this.listener = listener; } public OkHttpHelper get(String url) { Interceptor interceptor = new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); HttpUrl url1 = request.url(); String method = request.method(); Log.i("aaaa", "OkHttpHelper intercept: " + "url:" + url1 + " method:" + method); return chain.proceed(request); } }; OkHttpClient build = new OkHttpClient.Builder() .addInterceptor(interceptor).build(); Request request = new Request.Builder() .url(url) .build(); build.newCall(request).enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { Message message = new Message(); message.obj=e.getMessage(); message.what=1; handler.sendMessage(message); } @Override public void onResponse(Call call, Response response) throws IOException { Message message = new Message(); message.obj=response.body().string(); message.what=0; handler.sendMessage(message); } }); return this; } @SuppressLint("HandlerLeak") private Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); switch (msg.what) { case 0: String data = (String) msg.obj; listener.succeed(data); break; case 1: String error= (String) msg.obj; listener.failure(error); break; } } }; }
- import android.content.Intent;
- import android.os.Bundle;
- import android.support.v7.app.AppCompatActivity;
- import android.support.v7.widget.RecyclerView;
- import android.support.v7.widget.StaggeredGridLayoutManager;
- import android.view.View;
- import android.view.animation.AlphaAnimation;
- import android.view.animation.Animation;
- import android.widget.Button;
- import android.widget.TextView;
-
- import com.squareup.picasso.Picasso;
- import com.umeng.soexample.activity.AnimaActivity;
- import com.umeng.soexample.adapter.MyRecyclerViewAdapter;
-
- import java.util.ArrayList;
-
- import de.hdodenhof.circleimageview.CircleImageView;
-
-
- public class MainActivity extends AppCompatActivity implements View.OnClickListener {
-
- private CircleImageView mImgIcon;
- /**
- * XXXXX
- */
- private TextView mTxtName;
- private RecyclerView mRecyclerView;
- /**
- * 添加
- */
- private Button mBtnAdd;
- /**
- * 删除
- */
- private Button mBtnDelete;
-
- /**
- * 显示的数据
- */
- private ArrayList<String> mDatas;
-
- private StaggeredGridLayoutManager mStaggeredGridLayoutManager;
- private MyRecyclerViewAdapter mMyRecyclerViewAdapter;
- private Button mBtnAnima;
-
-
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- initView();
- //传值
- Intent intent = getIntent();
- String name = intent.getStringExtra("name");
- String pic = intent.getStringExtra("pic");
- mTxtName.setText(name);
- Picasso.with(this).load(pic).into(mImgIcon);
-
- initData();
- mStaggeredGridLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
- mRecyclerView.setLayoutManager(mStaggeredGridLayoutManager);
- mMyRecyclerViewAdapter = new MyRecyclerViewAdapter(this, mDatas);
- mRecyclerView.setAdapter(mMyRecyclerViewAdapter);
- initListener();
- }
-
- private void initListener() {
- //添加点击事件
- mMyRecyclerViewAdapter.setOnItemClickListener(new MyRecyclerViewAdapter.OnRecyclerItemClickListener() {
- @Override
- public void onItemClick(View view, int position) {
- mMyRecyclerViewAdapter.addItem(position, "添加的内容");
- }
- });
- //长按删除
- mMyRecyclerViewAdapter.setOnItemLongClickListener(new MyRecyclerViewAdapter.onRecyclerItemLongClickListener() {
- @Override
- public void onItemLongClick(View view, int position) {
- mMyRecyclerViewAdapter.removeItem(position);
- }
- });
- }
- //初始化数据
- protected void initData() {
- mDatas = new ArrayList<String>();
- for (int i = 'A'; i < 'z'; i++) {
- mDatas.add("" + (char) i);
- }
- }
-
-
- private void initView() {
- mImgIcon = (CircleImageView) findViewById(R.id.img_icon);
- mTxtName = (TextView) findViewById(R.id.txt_name);
- mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
- mBtnAnima = (Button) findViewById(R.id.btn_anima);
- mBtnAnima.setOnClickListener(this);
- /* mBtnDelete = (Button) findViewById(R.id.btn_delete);*/
- }
-
- @Override
- public void onClick(View v) {
- switch (v.getId()) {
- default:
- break;
- case R.id.btn_anima:
- startActivity(new Intent(MainActivity.this,AnimaActivity.class));
- break;
- }
- }
- }
- import android.content.Context;
- import android.support.v7.widget.RecyclerView;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.TextView;
-
- import com.umeng.soexample.R;
-
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
-
- /**
- * 实现瀑布流效果的适配器
- */
- public class MyRecyclerViewAdapter extends RecyclerView.Adapter<MyRecyclerViewAdapter.MyViewHolder> {
-
- private Context context;
- private List<String> list;//数据
- private List<Integer> heightList;//装产出的随机数
-
- private OnRecyclerItemClickListener mOnItemClickListener;//单击事件
- private onRecyclerItemLongClickListener mOnItemLongClickListener;//长按事件
-
-
- public MyRecyclerViewAdapter(Context context, List<String> list) {
- this.context = context;
- this.list = list;
- //记录为每个控件产生的随机高度,避免滑回到顶部出现空白
- heightList = new ArrayList<>();
- for (int i = 0; i < list.size(); i++) {
- int height = new Random().nextInt(200) + 100;//[100,300)的随机数
- heightList.add(height);
- }
- }
-
- @Override
- public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- //找到item的布局
- View view= LayoutInflater.from(context).inflate(R.layout.pinterest_view,parent,false);
- return new MyViewHolder(view);//将布局设置给holder
- }
-
- @Override
- public int getItemCount() {
- return list.size();
- }
-
- /**
- * 绑定视图到holder,就如同ListView的getView(),但是这里已经把复用实现了,我们只需要填充数据就行.
- * 由于在复用的时候都是调用该方法填充数据,但是上滑的时候,又会随机产生高度设置到控件上,这样当滑
- * 到顶部可能就会看到一片空白,因为后面随机产生的高度和之前的高度不一样,就不能填充屏幕了,所以
- * 需要记录每个控件产生的随机高度,然后在复用的时候再设置上去
- */
- @Override
- public void onBindViewHolder(final MyViewHolder holder, final int position) {
- //填充数据
- holder.textView.setText(list.get(position)+"");
- //由于需要实现瀑布流的效果,所以就需要动态的改变控件的高度了
- ViewGroup.LayoutParams params = holder.textView.getLayoutParams();
- params.height=heightList.get(position);
- holder.textView.setLayoutParams(params);
-
- //设置单击事件
- if(mOnItemClickListener !=null){
- holder.textView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- //这里是为textView设置了单击事件,回调出去
- //mOnItemClickListener.onItemClick(v,position);这里需要获取布局中的position,不然乱序
- mOnItemClickListener.onItemClick(v,holder.getLayoutPosition());
- }
- });
- }
- //长按事件
- if(mOnItemLongClickListener != null){
- holder.textView.setOnLongClickListener(new View.OnLongClickListener() {
- @Override
- public boolean onLongClick(View v) {
- //回调出去
- mOnItemLongClickListener.onItemLongClick(v,holder.getLayoutPosition());
- return true;//不返回true,松手还会去执行单击事件
- }
- });
- }
- }
-
- class MyViewHolder extends RecyclerView.ViewHolder{
-
- TextView textView;
-
- public MyViewHolder(View itemView) {
- super(itemView);
- textView = (TextView) itemView.findViewById(R.id.textView);
- }
- }
-
- /**
- * 处理item的点击事件,因为recycler没有提供单击事件,所以只能自己写了
- */
- public interface OnRecyclerItemClickListener {
- public void onItemClick(View view, int position);
- }
-
- /**
- * 长按事件
- */
- public interface onRecyclerItemLongClickListener{
- public void onItemLongClick(View view, int position);
- }
-
- /**
- * 暴露给外面的设置单击事件
- */
- public void setOnItemClickListener(OnRecyclerItemClickListener onItemClickListener){
- mOnItemClickListener = onItemClickListener;
- }
-
- /**
- * 暴露给外面的长按事件
- */
- public void setOnItemLongClickListener(onRecyclerItemLongClickListener onItemLongClickListener){
- mOnItemLongClickListener = onItemLongClickListener;
- }
-
- /**
- * 向指定位置添加元素
- */
- public void addItem(int position, String value) {
- if(position > list.size()) {
- position = list.size();
- }
- if(position < 0) {
- position = 0;
- }
- /**
- * 使用notifyItemInserted/notifyItemRemoved会有动画效果
- * 而使用notifyDataSetChanged()则没有
- */
- //在集合中添加这条数据
- list.add(position, value);
- //添加一个随机高度,会在onBindViewHolder方法中得到设置
- heightList.add(position,new Random().nextInt(200) + 100);
- //通知插入了数据
- notifyItemInserted(position);
- }
-
- /**
- * 移除指定位置元素
- */
- public String removeItem(int position) {
- if(position > list.size()-1) {
- return null;
- }
- //删除添加的高度
- heightList.remove(position);
- //所以还需要手动在集合中删除一次
- String value = list.remove(position);
- //通知删除了数据,但是没有删除list集合中的数据
- notifyItemRemoved(position);
- return value;
- }
-
- }
public class AnimaActivity extends AppCompatActivity { private static final int ANIMATION_TIME = 5000; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_anima); //图片渐变 AlphaAnimation alphaAnimation = new AlphaAnimation(0.1f, 1.0f); //渐变时间 alphaAnimation.setDuration(ANIMATION_TIME); //展示图片渐变动画 this.findViewById(R.id.anima_imgicon).setAnimation(alphaAnimation); //渐变监听效果 alphaAnimation.setAnimationListener(new Animation.AnimationListener() { /** * 动画开始 * @param animation */ @Override public void onAnimationStart(Animation animation) { System.out.println("动画开始"); } /** * 动画重复 * @param animation */ @Override public void onAnimationEnd(Animation animation) { System.out.println("动画重复"); } /** * 动画结束 * @param animation */ @Override public void onAnimationRepeat(Animation animation) { System.out.println("动画结束"); } }); } }
public class TwoActivity extends AppCompatActivity implements LoginView {
private ImageView imageView;
private TextView mingzi;
private RecyclerView recyclerView;
private List<User.DataBean> list = new ArrayList<>();
private String path = "http://www.xieast.com/api/news/news.php";
private MyRecyclerAdapter adapter;
private Button add;
private Button delete;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_two);
imageView = findViewById(R.id.touxiang);
mingzi = findViewById(R.id.mingzi);
recyclerView = findViewById(R.id.recyclerview);
add = findViewById(R.id.add);
delete = findViewById(R.id.jian);
Intent intent = getIntent();
String name = intent.getStringExtra("name");
String iconurl = intent.getStringExtra("iconurl");
imageView.setVisibility(View.VISIBLE);
mingzi.setText(name);
Picasso.with(TwoActivity.this).load(iconurl).into(imageView);
// OkHttpUtils utils = new OkHttpUtils();
NetProcenter netProcenter = new NetProcenter(this);
netProcenter.NetHttps(path);
}
@Override
public void LoginSuccess(String cheng) {
}
@Override
public void LoginError(String shi) {
}
@Override
public void onSuccess(final List<User.DataBean> list) {
list.addAll(list);
// adapter.setList(list);
adapter = new MyRecyclerAdapter(TwoActivity.this, list);
recyclerView.setAdapter(adapter);
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
adapter.setDj(new MyRecyclerAdapter.Dj() {
@Override
public void dj(View v, final int pisition) {
Toast.makeText(TwoActivity.this,"点击了",Toast.LENGTH_LONG).show();
Intent intent = new Intent(TwoActivity.this, ThreeActivity.class);
intent.putExtra("image",list.get(pisition).getThumbnail_pic_s());
startActivity(intent);
}
});
//添加和删除的功能
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adapter.addData(1);
}
});
delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adapter.deleteData(2);
}
});
}
}
public class MyRecyclerAdapter extends RecyclerView.Adapter<MyRecyclerAdapter.MyHolder> {
private Context context;
private List<User.DataBean> list;
public MyRecyclerAdapter(Context context, List<User.DataBean> list) {
this.context = context;
this.list = list;
}
@NonNull
@Override
public MyHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(context).inflate(R.layout.item, viewGroup, false);
return new MyHolder(view);
}
@Override
public void onBindViewHolder(@NonNull MyHolder myHolder, int i) {
User.DataBean bean = list.get(i);
//填充布局
Picasso.with(context).load(""+bean.getThumbnail_pic_s()).into(myHolder.imageView);
}
@Override
public int getItemCount() {
return list == null ? 0 : list.size();
}
//添加
public void addData(int position){
list.add(position,list.get(position));
notifyItemInserted(position);
notifyDataSetChanged();
}
//删除
public void deleteData(int position){
list.remove(position);
notifyItemRemoved(position);
notifyDataSetChanged();
}
class MyHolder extends RecyclerView.ViewHolder {
ImageView imageView;
public MyHolder(@NonNull View itemView) {
super(itemView);
imageView = itemView.findViewById(R.id.imageview);
//瀑布流
ViewGroup.LayoutParams layoutParams = imageView.getLayoutParams();
layoutParams.width=300;
layoutParams.height=(int)(Math.random()*400+200);
imageView.setLayoutParams(layoutParams);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dj.dj(v,getAdapterPosition());
}
});
}
}
public void setDj(Dj dj) {
this.dj = dj;
}
private Dj dj;
public MyRecyclerAdapter(Dj dj) {
this.dj = dj;
}
public interface Dj{
void dj(View v,int pisition);
}
}
public class ThreeActivity extends AppCompatActivity {
private ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_three);
imageView = findViewById(R.id.imageviewt);
Intent intent = getIntent();
String image1 = intent.getStringExtra("image");
Picasso.with(getApplicationContext()).load(image1).into(imageView);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ObjectAnimator animator1 = ObjectAnimator.ofFloat(v,"translationY",200);
ObjectAnimator animator2 = ObjectAnimator.ofFloat(v,"alpha",0,1);
ObjectAnimator animator3 = ObjectAnimator.ofFloat(v,"rotation",360);
ObjectAnimator animator4 = ObjectAnimator.ofFloat(v,"scaleX",2,1);
AnimatorSet set = new AnimatorSet();
set.playTogether(animator1,animator2,animator3,animator4);
set.setDuration(3000);
set.start();
}
});
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。