Android——“i分享”APP开发Day11

通过前面一篇,“我的”页面的后台就搭建完整了,接下来就继续处理一下Android端下“我的”页面剩余还未完成的功能——修改密码、查看我的分享、查看我的日记、查看我的收藏、查看iShare相关

1.修改密码的页面设计——activity_change_password.xml

  • 页面包括旧密码输入框、新密码输入框,具体代码如下:
<?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:background="#eeeeee">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:background="@color/color_minefragment_top"
        >
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAlignment="center"
            android:text="修改密码"
            android:textColor="#fff"
            android:textSize="20dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="20dp"
            />
    </RelativeLayout>
    <LinearLayout
        android:id="@+id/password_change_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_marginTop="120dp"
        android:layout_marginLeft="50dp"
        android:layout_marginRight="50dp"
        >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="旧 密 码:"

                android:textSize="@dimen/textSize_normal"/>
            <EditText
                android:id="@+id/et_old_login_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="@dimen/textSize_normal"
                android:inputType="textPassword"

                android:hint="这里填写旧密码"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="12dp">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="@dimen/textSize_normal"
                android:text="新 密 码:"/>
            <EditText
                android:id="@+id/et_new_login_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="@dimen/textSize_normal"
                android:inputType="textPassword"
                android:hint="这里填写新密码"/>
        </LinearLayout>
    </LinearLayout>


    <Button
        android:id="@+id/bt_change_password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/password_change_layout"
        android:layout_marginTop="20dp"
        android:layout_marginLeft="150dp"
        android:layout_marginRight="150dp"
        android:background="@drawable/selector_loginactivity_button"
        android:text="修改"
        android:textColor="#fff"
        android:gravity="center"
        android:onClick="onClick"
        />
    <TextView
        android:id="@+id/bt_changePassword_view_info"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginVertical="30dp"

        android:text="信息反馈"
        android:textColor="#B3B3B3"
        android:gravity="center"
        />
</RelativeLayout>

2.修改密码页面的逻辑

  • 在之前创建好的com.example.discover包中创建class命名为ChangePassword.java
  • 在AndroidManifest.xml中添加配置:
<activity android:name=".ChangePassword"
    android:label="更改密码">
</activity>
  • ChangePassword.java文件处理的逻辑就是获取到用户的昵称、用户输入的旧密码、用户输入的新密码,然后请求已经创建好的servlet——ChangePassword,然后得到是否修改成功的返回信息,ChangePassword.java文件具体代码如下
package com.example.discover;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class ChangePassword extends Activity {
    EditText old_pass_et;   //旧密码
    EditText new_pass_et;   //新密码
    Button sure_change_pass;   //确定修改
    String baseUrl = "http://10.0.2.2:8080/iShareService/servlet/";   //web服务器的地址
    String imgBaseUrl = "http://10.0.2.2:8080/iShareService/images/";  //图片资源
    String userName,oldPass,newPass;   //存放用户基本信息

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_password);

        old_pass_et = (EditText) findViewById(R.id.et_old_login_password); //新密码
        new_pass_et = (EditText) findViewById(R.id.et_new_login_password); //新密码
        sure_change_pass = (Button)findViewById(R.id.bt_change_password) ;//确定修改密码的按钮

        setBaseInfo();
        sure_change_pass.setOnClickListener(new ChangePassword.onClick());
    }

    class onClick implements View.OnClickListener {
        @Override
        public void onClick(View v) {
            oldPass = old_pass_et.getText().toString();
            newPass = new_pass_et.getText().toString();
            StringBuilder stringBuilder = new StringBuilder();
            BufferedReader buffer = null;
            HttpURLConnection connGET = null;
            if(oldPass.length()==0||newPass.length()==0){
                Toast.makeText(ChangePassword.this, "密码不能为空", Toast.LENGTH_LONG).show();
                return;
            }

            try {
                String registerUrl = baseUrl+"ChangePassword?oldPass="+oldPass+"&newPass="+newPass+"&username="+userName;
                URL url = new URL(registerUrl);
                connGET = (HttpURLConnection) url.openConnection();
                connGET.setConnectTimeout(5000);
                connGET.setRequestMethod("GET");
                if (connGET.getResponseCode() == 200) {
                    buffer = new BufferedReader(new InputStreamReader(connGET.getInputStream()));
                    for (String s = buffer.readLine(); s != null; s = buffer.readLine()) {
                        stringBuilder.append(s);
                    }
                    Toast.makeText(ChangePassword.this, stringBuilder.toString(), Toast.LENGTH_LONG).show();

                    //通过handler设置延时1秒后执行r任务,跳转到我的页面
                    new Handler().postDelayed(new ChangePassword.LoadMainTask(),500);
                    buffer.close();
                }else{
                    Toast.makeText(ChangePassword.this,"非200.."+connGET.getResponseCode() , Toast.LENGTH_LONG).show();
                }
            } catch (Exception e) {
                e.printStackTrace();
                Toast.makeText(ChangePassword.this, "get 提交 err.." + e.toString(), Toast.LENGTH_LONG).show();
            }


        }
    }

    //启动线程,加载我的页面
    private class LoadMainTask implements Runnable{
        @Override
        public void run() {
            Intent intent = new Intent(ChangePassword.this,MyTabFragment.class);
            /*startActivity(intent);*/
            setResult(2, intent); //这里的2就对应到onActivityResult()方法中的resultCode
            finish();
        }
    }

    //获取用户信息
    public void setBaseInfo(){
        //获取最新的登录状态,SharePreferences为永久存储,需要手动退出
        SharedPreferences sp = ChangePassword.this.getSharedPreferences("save", Context.MODE_PRIVATE);
        userName = sp.getString("name","");
    }
}

 

3.我的分享、我的日记、我的收藏 页面设计

  • 这三个功能按钮都是跳转到的页面其实是同一个,只不过内容获取是不一样的,所以在这里只需要写一个详情页就可以了
  • 在layout下新建activity_about_me.xml文件,在该布局下就只需要要一个ListView就可以了,详细代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        android:orientation="vertical"
        android:paddingTop="20dp"
        android:paddingBottom="20dp">

        <ListView
            android:id="@+id/my_share_listView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:dividerHeight="15dp" />
    </LinearLayout>
</LinearLayout>

4.我的分享、我的日记、我的收藏 页面的逻辑

  • 在已经创建好的com.example.discover包中创建class——MyShareList.java
  • 因为是跳转页面,所以在AndroidMainifest.xml中要添加配置
<activity android:name=".MyShareList"
    android:label="关于我的">
</activity>
  • 该文件处理的主要部分就是,获取到上一个页面传递的type(用于判断请求的是我的分享、我的日记还是我的收藏),然后获取到该用户的昵称,通过这两个参数请求后台的servlet——QueryAboutMe.java,返回相对应类型的内容,MyShareList.java具体代码如下:
package com.example.discover;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import android.os.StrictMode;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.bean.FindInfo;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;

public class MyShareList extends Activity implements AbsListView.OnScrollListener{
    Activity mActivity;     //存放当前的activity
    String baseUrl = "http://10.0.2.2:8080/iShareService/servlet/";   //web服务器的地址
    String imgBaseUrl = "http://10.0.2.2:8080/iShareService/images/";  //图片资源
    int requestType=0;   //请求类型,0:我的分享、1:我的日记;2:我的收藏
    String userName="";
    String requestUrl="";


    private TextView title;
    private MyShareList.PaginationAdapter adapterAction;
    private ScheduledExecutorService scheduledExecutorService;

    private ListView listView;
    private int page = 1; //请求页数
    private int count = 10; //每次请求的数量
    private int visibleLastIndex = 0;  //最后的可视项索引
    private int visibleItemCount;    // 当前窗口可见项总数
    private int dataSize = 28;     //数据集的条数
    private MyShareList.PaginationAdapter adapter;
    private View loadMoreView;
    private Button loadMoreButton;
    private Handler handler = new Handler();

    //返回测试信息
    /*TextView testTxt;*/
    public  void refreshDiscover(){
        page = 1;
        visibleLastIndex = 0;
        listView.setAdapter(null);   //将ListView控件的内容清空
        initializeAdapter();
        listView.setAdapter(adapter);
        adapter.notifyDataSetChanged();
    }
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about_me);
        mActivity = MyShareList.this;

        //取得启动该Activity的Intent对象
        Intent intent =getIntent();
        //获取最新的登录状态,SharePreferences为永久存储,需要手动退出
        SharedPreferences sp = MyShareList.this.getSharedPreferences("save", Context.MODE_PRIVATE);
        userName = sp.getString("name","");

        requestType =intent.getIntExtra("requestType",0);
        //取出Intent中附加的数据
        if(requestType==0){
            requestUrl = baseUrl+"QueryAboutMe?username="+userName+"&type=0&page="+page+"&count="+count;
        }else if(requestType==1){
            requestUrl = baseUrl+"QueryAboutMe?username="+userName+"&type=1&page="+page+"&count="+count;
        }else{
            requestUrl = baseUrl+"QueryAboutMe?username="+userName+"&type=2&page="+page+"&count="+count;
        }

        loadMoreView = getLayoutInflater().inflate(R.layout.activity_find_loadmore, null);
        loadMoreButton = (Button)loadMoreView.findViewById(R.id.loadMoreButton);
        loadMoreButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                loadMoreButton.setText("正在加载中...");  //设置按钮文字
                handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        loadMoreData();
                        adapter.notifyDataSetChanged();
                        loadMoreButton.setText("查看更多..."); //恢复按钮文字
                    }
                },2000);

            }
        });

        //返回测试信息
        /* testTxt = (TextView)getActivity().findViewById(R.id.test_discover_tab);*/

        listView = (ListView)findViewById(R.id.my_share_listView);
        listView.addFooterView(loadMoreView);  //设置列表底部视图
        initializeAdapter();
        listView.setAdapter(adapter);
        listView.setOnScrollListener(this);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TextView getTvId = (TextView)view.findViewById(R.id.cardId);
                /*Toast.makeText(mActivity,"点击了"+getTvId.getText().toString()+"id", Toast.LENGTH_SHORT).show();*/
                SharedPreferences sp = mActivity.getSharedPreferences("save", Context.MODE_PRIVATE);
                Boolean isLogin = sp.getBoolean("isLogin",false);

                if(isLogin){
                    //点击了进入详情
                    Intent display_info_intent = new Intent();
                    display_info_intent.setClass(mActivity, DisplayDetail.class);  //创建intent对象,并制定跳转页面
                    display_info_intent.putExtra("infoId",getTvId.getText().toString());
                    mActivity.setResult(1, display_info_intent); //这里的1就对应到onActivityResult()方法中的resultCode
                    startActivity(display_info_intent);    //跳转到详情页面
                }else{
                    //尚未登录
                    Toast.makeText(MyShareList.this,"请先登录", Toast.LENGTH_LONG).show();
                }

            }
        });
    }

    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
        int itemsLastIndex = adapter.getCount()-1; //数据集最后一项的索引
        int lastIndex = itemsLastIndex + 1;
        if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE
                && visibleLastIndex == lastIndex) {
            // 如果是自动加载,可以在这里放置异步加载数据的代码
        }
    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem,
                         int visibleItemCount, int totalItemCount) {
        this.visibleItemCount = visibleItemCount;
        visibleLastIndex = firstVisibleItem + visibleItemCount - 1;  //最后的可视项索引

        //如果所有的记录选项等于数据集的条数,则移除列表底部视图
        if(totalItemCount == dataSize+1){
            listView.removeFooterView(loadMoreView);
            Toast.makeText(MyShareList.this,  "数据全部加载完!", Toast.LENGTH_LONG).show();
        }
    }
    /**
     * 查询数据库中的数据
     */
    private JSONArray loadDataFromDataBase(String loadDataUrl){
        StringBuilder stringBuilder = new StringBuilder();
        BufferedReader buffer = null;
        HttpURLConnection connGET = null;

        try {
            URL url = new URL(loadDataUrl);
            connGET = (HttpURLConnection) url.openConnection();
            connGET.setConnectTimeout(5000);
            connGET.setRequestMethod("GET");
            if (connGET.getResponseCode() == 200) {
                buffer = new BufferedReader(new InputStreamReader(connGET.getInputStream()));
                for (String s = buffer.readLine(); s != null; s = buffer.readLine()) {
                    stringBuilder.append(s);
                }

                if(stringBuilder.toString()!="null"){
                    //返回测试信息
                    JSONArray jsonArray = new JSONArray(stringBuilder.toString());

                    //获取到的数据,对Json进行解析
                    page = page+1;  //一次成功请求后更新请求页面
                    buffer.close();
                    return jsonArray;
                }else{
                    return null;
                }

            }else{
                Toast.makeText(MyShareList.this,"非200", Toast.LENGTH_LONG).show();
            }
        } catch (Exception e) {
            e.printStackTrace();
            Toast.makeText(MyShareList.this, "get 提交 err.." + e.toString(), Toast.LENGTH_LONG).show();
        }
        return null;
    }

    //初始化将详情设置到FindInfo bean中
    public List<FindInfo> initSetDataToBean(String detail){
        List<FindInfo> findInfo = new ArrayList<FindInfo>();
        try {
            JSONArray detailJsonArray = new JSONArray(detail);
            for (int i = 0; i < detailJsonArray.length(); i++) {
                FindInfo items = new FindInfo();

                JSONObject temp = (JSONObject) detailJsonArray.get(i);

                Integer infoId = temp.getInt("infoId");    //内容ID
                String infoTitle = temp.getString("infoTitle");   //内容标题
                String infoDescribe = temp.getString("infoDescribe");   //内容简述
                String infoDetail = temp.getString("infoDetail");   //内容详情
                Integer type = temp.getInt("infoType");    //类型:0表示日记,1表示趣事
                Integer support = temp.getInt("infoSupport");   //点赞数
                String infoAuthor = temp.getString("infoAuthor");  //作者

                items.setInfoId(infoId);
                items.setInfoTitle(infoTitle);
                items.setInfoDescribe(infoDescribe);
                items.setInfoDetail(infoDetail);
                items.setType(type);
                items.setSupport(support);
                items.setInfoAuthor(infoAuthor);

                findInfo.add(items);
            }
            return findInfo;

        }catch (JSONException e){
            Toast.makeText(MyShareList.this, "initSetDataToBean异常 err.." + e.toString(), Toast.LENGTH_LONG).show();
            return null;
        }
    }


    //加载更多将详情设置到FindInfo bean中
    public void loadMoreSetDataToBean(String detail){

        try {
            JSONArray detailJsonArray = new JSONArray(detail);

            for (int i = 0; i < detailJsonArray.length(); i++) {
                FindInfo items = new FindInfo();
                JSONObject temp = (JSONObject) detailJsonArray.get(i);
                Integer infoId = temp.getInt("infoId");    //内容ID
                String infoTitle = temp.getString("infoTitle");   //内容标题
                String infoDescribe = temp.getString("infoDescribe");   //内容简述
                String infoDetail = temp.getString("infoDetail");   //内容详情

                Integer type = temp.getInt("infoType");    //类型:0表示日记,1表示趣事
                Integer support = temp.getInt("infoSupport");   //点赞数
                String infoAuthor = temp.getString("infoAuthor");  //作者

                items.setInfoId(infoId);
                items.setInfoTitle(infoTitle);
                items.setInfoDescribe(infoDescribe);
                items.setInfoDetail(infoDetail);
                items.setType(type);
                items.setSupport(support);
                items.setInfoAuthor(infoAuthor);

                adapter.addNewsItem(items);   //与初始化是有差异的
            }

        }catch (JSONException e){
            Toast.makeText(MyShareList.this, "loadMoreSetDataToBean异常 err.." + e.toString(), Toast.LENGTH_LONG).show();
        }

    }
    /**
     * 初始化ListView的适配器,即打开页面展示的数据
     */
    private void initializeAdapter(){
        // 设置线程策略
        setVersion();
        JSONArray jsonArray = loadDataFromDataBase(requestUrl);

        if(jsonArray!=null){
            try {
                JSONObject totalObject = (JSONObject)jsonArray.get(0);

                dataSize = totalObject.getInt("totalRecord");  //总记录数
                String detail= totalObject.getString("RecordDetail");   //详情

                if(initSetDataToBean(detail)!=null) {
                    adapter = new MyShareList.PaginationAdapter(initSetDataToBean(detail));   //将详情设置到bean中
                }

            }catch (JSONException e){
                Toast.makeText(MyShareList.this, "initializeAdapter异常 err.." + e.toString(), Toast.LENGTH_LONG).show();
            }
        }else{
            listView.removeFooterView(loadMoreView);
            Toast.makeText(MyShareList.this, "查询为空" , Toast.LENGTH_LONG).show();
        }
    }

    //APP如果在主线程中请求网络操作,将会抛出异常,所以需要用线程来操作网络请求
    void setVersion() {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectDiskReads()
                .detectDiskWrites()
                .detectNetwork()
                .penaltyLog()
                .build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectLeakedSqlLiteObjects() //探测SQLite数据库操作
                .penaltyLog() //打印logcat
                .penaltyDeath()
                .build());
    }



    /**
     * 加载更多数据
     */
    private void loadMoreData(){
        JSONArray jsonArray = loadDataFromDataBase(requestUrl);

        try {
            JSONObject total = (JSONObject) jsonArray.get(0);
            dataSize = total.getInt("totalRecord");  //总记录数
            String detail= total.getString("RecordDetail");   //详情

            loadMoreSetDataToBean(detail);   //将更多的详情设置到bean中
        }catch (JSONException e){
            Toast.makeText(MyShareList.this, "loadMoreData()异常 err.." + e.toString(), Toast.LENGTH_LONG).show();
        }

    }


    /**
     * 将一组数据传到ListView等UI显示组件
     */
    class PaginationAdapter extends BaseAdapter {

        List<FindInfo> newsItems;

        public PaginationAdapter(List<FindInfo> newsitems) {
            this.newsItems = newsitems;
        }

        @Override
        public int getCount() {
            return newsItems.size();
        }

        @Override
        public Object getItem(int position) {
            return newsItems.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }


        //在这里将Item设置到每个卡片
        @Override
        public View getView(int position, View view, ViewGroup parent) {
            if (view == null) {
                view = getLayoutInflater().inflate(R.layout.activity_find_list_item, null);
            }

            //标题
            TextView tvTitle = (TextView) view.findViewById(R.id.cardTitle);
            tvTitle.setText(newsItems.get(position).getInfoTitle());

            //文章ID
            TextView tvId = (TextView) view.findViewById(R.id.cardId);
            tvId.setText(newsItems.get(position).getInfoId().toString());

            int type = newsItems.get(position).getType();

            if (type == 0 || type == 3) {
                ImageView cardImgTip = (ImageView) view.findViewById(R.id.cardImgTip);
                if (type == 0) {
                    cardImgTip.setImageResource(R.drawable.share_funny_select);
                } else {
                    cardImgTip.setImageResource(R.drawable.share_diary_select);
                }

                TextView tvContent = (TextView) view.findViewById(R.id.cardContent);
                tvContent.setVisibility(View.VISIBLE);  //显示文字框

                ImageView ivContent = (ImageView) view.findViewById(R.id.cardContent_pic);
                ivContent.setVisibility(View.GONE);   //设置图片显示框隐藏

                LinearLayout layoutMusic = (LinearLayout) view.findViewById(R.id.cardContent_music);
                layoutMusic.setVisibility(View.GONE);   //设置音乐显示框隐藏

                //分享的普通内容

                tvContent.setText(newsItems.get(position).getInfoDescribe());
            } else if (type == 1) {
                ImageView cardImgTip = (ImageView) view.findViewById(R.id.cardImgTip);
                cardImgTip.setImageResource(R.drawable.share_pic_select);
                //分享图片
                TextView tvContent = (TextView) view.findViewById(R.id.cardContent);
                tvContent.setVisibility(View.GONE);  //隐藏文字框
                LinearLayout layoutMusic = (LinearLayout) view.findViewById(R.id.cardContent_music);
                layoutMusic.setVisibility(View.GONE);   //设置音乐显示框隐藏

                ImageView ivContent = (ImageView) view.findViewById(R.id.cardContent_pic);
                //通过网络链接获取图片
                Bitmap one;
                String describeUrl = newsItems.get(position).getInfoDescribe().trim();
                try {
                    one = LoadImgByNet.getBitmap(imgBaseUrl + describeUrl);  //设置图片
                    ivContent.setImageBitmap(one);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                ivContent.setVisibility(View.VISIBLE);   //设置图片显示框

            } else if (type == 2) {
                ImageView cardImgTip = (ImageView) view.findViewById(R.id.cardImgTip);
                cardImgTip.setImageResource(R.drawable.share_music_select);

                //分享的音乐
                TextView tvContent = (TextView) view.findViewById(R.id.cardContent);
                tvContent.setVisibility(View.GONE);  //显示文字框
                ImageView ivContent = (ImageView) view.findViewById(R.id.cardContent_pic);
                ivContent.setVisibility(View.GONE);   //设置图片显示框隐藏

                LinearLayout layoutMusic = (LinearLayout) view.findViewById(R.id.cardContent_music);

                TextView tvMusicContent = (TextView) view.findViewById(R.id.cardTitle_music);
                tvMusicContent.setText(newsItems.get(position).getInfoDescribe());

                layoutMusic.setVisibility(View.VISIBLE);   //设置音乐显示框显示
            }

            return view;
        }

        /**
         * 添加数据列表项
         *
         * @param infoItem
         */
        public void addNewsItem(FindInfo infoItem) {
            newsItems.add(infoItem);
        }
        }
    }

 

5.iShare相关页面设计

  • 在layout下新建文件activity_about_ishare.xml,具体代码如下
  • 这个页面设计比较简单,主要就是介绍iShare应用的开发目的和实现功能,没有功能,只是展示信息
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fadingEdge="none" >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:paddingLeft="14dp"
            android:paddingRight="14dp"
            android:paddingBottom="60dp"
            android:orientation="vertical">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="22dp"
                android:textStyle="bold"
                android:text="关于iShare" />
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:textSize="18sp"
                    android:layout_weight="1"
                    android:textColor="#000000"
                    android:text="开发者学号:\n
                    201611671208\n
                    201611671206\n
                    201611671221\n
                     " />

            </LinearLayout>

            <TextView
                android:background="@drawable/list_card_style"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/margin_10"
                android:padding="10dp"
                android:textSize="18sp"
                android:textColor="#000000"
                android:text="iShare应用:发现有趣的人和事,在这个平台可以发布自己感兴趣的内容以及查看大家的分享,简历良好的交流氛围"/>
            <TextView
                android:id="@+id/detail_info_detail"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/margin_10"
                android:padding="10dp"
                android:textSize="18sp"
                android:textColor="#000000"
                android:singleLine="false"
                android:text="  开发目的:Android课程设计\n\n

开发时间:2019年5月\n\n

素材来源:LOGO是网络资源图,Icon来自www.iconfont.cn,其中用于测试的图片均来自网络\n\n

项目代码:部分结构参考自CSDN、GitHub\n\n

实现功能:起始页、注册、登录、更新签名、更改密码、浏览分享、按标题和简述关键字查找分享的内容、根据用户昵称查找用户、查看分享详情、点赞、收藏、发布四种类型的内容、查看按点赞数排行前十的内容、删除发布的内容、评论、查看我的分享、查看我的日记、查看我的收藏" />


        </LinearLayout>
    </ScrollView>
</LinearLayout>

6.“我的”页面跳转事件

  • 打开之前创建好的MyTabFragment.java文件,给对应的五个Button——“修改密码”、“查看我的分享”、“查看我的日记”、“查看我的收藏”、“查看iShare相关”添加点击监听
//“我的”页面中相关点击事件
    class mClick implements View.OnClickListener {

        public void onClick(View v) {
            if(isLogin) {
                if (v == account_set_bt) {
                    //点击了账号管理
                    Intent account_manage_intent = new Intent();
                    account_manage_intent.setClass(mActivity, AccountManagement.class);  //创建intent对象,并制定跳转页面
                    startActivity(account_manage_intent);    //跳转到账号管理页面

                /*TextView textView = (TextView) getActivity().findViewById(R.id.test_text_view);  //用于放测试的提示信息
                Toast.makeText(getActivity(), textView.getText(), Toast.LENGTH_LONG).show();*/
                }else if(v == signature_set_bt){
                    //点击了更改签名
                    Intent signature_manage_intent = new Intent();
                    signature_manage_intent.setClass(mActivity, ChangeSignature.class);  //创建intent对象,并指定跳转页面
                    //startActivity(signature_manage_intent);    //跳转到更新签名页面
                    startActivityForResult(signature_manage_intent,1);   //需要返回该页面
                }else if(v == password_set_bt){
                    //点击了更改密码
                    Intent password_manage_intent = new Intent();
                    password_manage_intent.setClass(mActivity, ChangePassword.class);  //创建intent对象,并指定跳转页面
                    /*startActivity(password_manage_intent);   */
                    startActivityForResult(password_manage_intent,2);   // 跳转到修改密码页面
                }else if(v == share_list_bt){
                    //点击了我的分享
                    Intent intent = new Intent();
                    intent.setClass(mActivity, MyShareList.class);  //创建intent对象,并指定跳转页面
                    intent.putExtra("requestType",0);
                    mActivity.setResult(4, intent); //这里的4就对应到onActivityResult()方法中的resultCode
                    startActivity(intent);    //跳转到list
                }else if(v==diary_list_bt){
                    //点击了我的日记
                    Intent intent = new Intent();
                    intent.setClass(mActivity, MyShareList.class);  //创建intent对象,并指定跳转页面
                    intent.putExtra("requestType",1);
                    mActivity.setResult(5, intent); //这里的4就对应到onActivityResult()方法中的resultCode
                    startActivity(intent);    //跳转到list
                }else if(v==focus_list_bt){
                    //点击了我的收藏
                    Intent intent = new Intent();
                    intent.setClass(mActivity, MyShareList.class);  //创建intent对象,并指定跳转页面
                    intent.putExtra("requestType",2);
                    mActivity.setResult(6, intent); //这里的4就对应到onActivityResult()方法中的resultCode
                    startActivity(intent);    //跳转到list
                } else if(v==about_iShare){
                    //点击了关于iShare
                    Intent about_iShare_intent = new Intent();
                    about_iShare_intent.setClass(mActivity, AboutIShare.class);  //创建intent对象,并指定跳转页面
                    startActivity(about_iShare_intent);    //跳转到iShare介绍页面
                }
            }else{

                Toast.makeText(getActivity(), "请先登录!", Toast.LENGTH_LONG).show();
            }
        }
    }

 

——到这整个iShare项目就开发完成了,整个过程可能会有部分代码或者配置不是很完整,接下来将会分模块写一下整个项目的详细代码,以及如何运行整个项目 和运行的结果

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值