漫吧漫画阅读界面的搭建(一)基础布局搭建(完全代码)

来源:互联网 发布:国家数据网 编辑:程序博客网 时间:2024/05/22 06:29

第一篇链接 漫吧漫画阅读界面的搭建(一)基础布局搭建(上)

第二篇链接漫吧漫画阅读界面的搭建(一)基础布局搭建(下)

这一篇是完整代码的展示,博文是前两篇

方便起见,代码为一个文件

布局代码:

主布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"             xmlns:tools="http://schemas.android.com/tools"             android:layout_width="match_parent"             android:layout_height="match_parent"                android:background="@color/colorSliteGray"             tools:context="winter.zxb.smilesb101.cartoon8.WatchComicActivity">    <!-- The primary full-screen view. This can be replaced with whatever view         is needed to present your content, e.g. VideoView, SurfaceView,         TextureView, etc. -->    <android.support.v7.widget.RecyclerView        android:id="@+id/fullscreen_content"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:gravity="center"/>    <!--底部小的状态栏-->    <LinearLayout        android:id="@+id/small_status"        android:layout_width="wrap_content"        android:layout_height="30dp"        android:layout_alignParentEnd="true"        android:layout_alignParentBottom="true"        android:background="@drawable/round_rect_pressed"        android:orientation="horizontal">        <TextView            android:id="@+id/comic_name_bottom"            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:textColor="@color/colorSliteGray"            android:gravity="center"            android:layout_marginLeft="2dp"            android:maxLines="1"            android:textSize="12sp"/>        <TextView            android:id="@+id/comic_pic_state"            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:gravity="center"            android:textColor="@color/colorSliteGray"            android:layout_marginLeft="10dp"            android:maxLines="1"            android:textSize="12sp"/>        <TextView            android:id="@+id/time"            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:gravity="center"            android:textColor="@color/colorSliteGray"            android:layout_marginLeft="10dp"            android:maxLines="1"            android:textSize="12sp"/>        <TextView            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:gravity="center"            android:textColor="@color/colorSliteGray"            android:text="@string/battery"            android:layout_marginLeft="10dp"            android:maxLines="1"            android:textSize="12sp"/>        <TextView            android:id="@+id/battery"            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:gravity="center"            android:maxLines="1"            android:textColor="@color/colorSliteGray"            android:layout_marginRight="20dp"            android:textSize="12sp"/>    </LinearLayout>    <!--菜单按钮区域(实际作用区域)-->    <LinearLayout        android:id="@+id/menu_ctrl"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:orientation="vertical"        android:visibility="visible">        <!--上一话-->        <TextView            android:id="@+id/preHUAText"            android:layout_width="match_parent"            android:layout_height="0dp"            android:layout_weight="1">        </TextView>        <!--显示或者隐藏状态栏的触发器-->        <TextView            android:id="@+id/toogle"            android:layout_width="match_parent"            android:layout_height="0dp"            android:layout_weight="1"            android:layout_centerInParent="true"></TextView>        <!--下一话-->        <TextView            android:id="@+id/nextHUAText"            android:layout_width="match_parent"            android:layout_height="0dp"            android:layout_weight="1">        </TextView>    </LinearLayout>    <!--菜单按钮效果效果区域-->    <LinearLayout        android:id="@+id/menu_content"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:orientation="vertical"        android:visibility="gone">        <!--上一话-->        <TextView            android:layout_width="match_parent"            android:layout_height="0dp"            android:layout_weight="1"            android:text="@string/preHUA"            android:textColor="@color/colorWrite"            android:background="#50000000"            android:gravity="center"            android:textSize="30sp">        </TextView>        <!--显示或者隐藏状态栏的触发器-->        <TextView            android:layout_width="match_parent"            android:layout_height="0dp"            android:layout_weight="1"            android:layout_centerInParent="true"            android:background="#50000000"            android:textSize="30sp"            android:text="@string/menu"            android:textColor="@color/colorWrite"            android:gravity="center"            android:layout_marginTop="10dp"            android:layout_marginBottom="10dp"></TextView>        <!--下一话-->        <TextView            android:layout_width="match_parent"            android:layout_height="0dp"            android:layout_weight="1"            android:text="@string/nextHUA"            android:textColor="@color/colorWrite"            android:background="#50000000"            android:gravity="center"            android:textSize="30sp">        </TextView>    </LinearLayout>    <!--顶部栏-->    <LinearLayout        android:id="@+id/top_layout"        android:layout_width="match_parent"        android:layout_height="50dp"        android:orientation="horizontal"        android:background="#80000000"        android:visibility="gone">        <LinearLayout            android:layout_width="0dp"            android:layout_height="match_parent"            android:layout_weight="1"            android:orientation="horizontal">            <Button                android:id="@+id/back_btn"                android:layout_width="10dp"                android:layout_height="20dp"                android:layout_gravity="center_vertical"                android:layout_marginLeft="15dp"                android:background="@mipmap/arrow_left_better"/>            <TextView                android:id="@+id/comic_name"                android:layout_width="wrap_content"                android:layout_height="30dp"                android:layout_gravity="center_vertical"                android:gravity="center"                android:layout_marginLeft="10dp"                android:textColor="@color/colorWrite"/>            <TextView                android:id="@+id/comic_pic_state_top"                android:layout_width="wrap_content"                android:layout_height="30dp"                android:layout_marginLeft="10dp"                android:textColor="@color/colorWrite"                android:layout_gravity="center_vertical"                android:gravity="center"/>        </LinearLayout>        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:orientation="horizontal"            android:layout_marginLeft="10dp">            <Button                android:id="@+id/show_menuBtn"                android:layout_width="20dp"                android:layout_height="20dp"                android:background="@mipmap/info_72px"                android:layout_marginRight="10dp"                android:layout_gravity="center_vertical"                android:layout_marginLeft="10dp"/>            <Button                android:id="@+id/feed_backBtn"                android:layout_width="20dp"                android:layout_height="20dp"                android:background="@mipmap/edit_71"                android:layout_marginRight="10dp"                android:layout_gravity="center_vertical"                android:layout_marginLeft="10dp"/>            <Button                android:id="@+id/downloadpic_Btn"                android:layout_width="20dp"                android:layout_height="20dp"                android:background="@mipmap/download_46"                android:layout_marginRight="10dp"                android:layout_gravity="center_vertical"                android:layout_marginLeft="10dp"/>            <Button                android:id="@+id/sharePicBtn"                android:layout_width="20dp"                android:layout_height="20dp"                android:background="@mipmap/external_link_75"                android:layout_marginRight="20dp"                android:layout_gravity="center_vertical"                android:layout_marginLeft="10dp"/>        </LinearLayout>    </LinearLayout>    <!--SeekBar的操作提示栏,默认不可见,按下SeekBar可见,抬起不可见-->    <RelativeLayout        android:id="@+id/bottom_seekBar_help"        android:layout_width="match_parent"        android:layout_height="30dp"        android:layout_above="@+id/bottom_layout"        android:layout_marginBottom="10dp"        android:background="#80000000"        android:visibility="gone">        <LinearLayout            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:orientation="horizontal"            android:layout_centerInParent="true">            <TextView                android:id="@+id/seekBar_help_now"                android:layout_width="wrap_content"                android:layout_height="match_parent"                android:gravity="center"                android:layout_gravity="center"                android:textColor="@color/colorAqua"/>            <TextView                android:layout_width="wrap_content"                android:layout_height="match_parent"                android:gravity="center"                android:layout_gravity="center"                android:text=" / "                android:textColor="@color/colorSliteGray"/>            <TextView                android:id="@+id/seekBar_help_num"                android:layout_width="wrap_content"                android:layout_height="match_parent"                android:layout_gravity="center"                android:gravity="center"                android:textColor="@color/colorSliteGray"/>        </LinearLayout>    </RelativeLayout>    <!--底部栏--><LinearLayout    android:id="@+id/bottom_layout"    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:orientation="vertical"    android:layout_alignParentBottom="true"    android:background="#80000000"    android:visibility="gone">    <LinearLayout        android:layout_width="match_parent"        android:layout_height="50dp"        android:orientation="horizontal"        android:layout_marginBottom="10dp"        android:layout_marginLeft="15dp"        android:layout_marginRight="15dp"        android:layout_marginTop="10dp">        <TextView            android:id="@+id/preHUA"            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="@string/preHUA"            android:textColor="@color/colorSliteGray"            android:gravity="center"/>        <SeekBar            android:id="@+id/bottom_seekBar"            android:layout_width="0dp"            android:layout_height="wrap_content"            android:layout_marginLeft="10dp"            android:layout_marginRight="10dp"            android:layout_weight="1"            android:layout_gravity="center"/>        <TextView            android:id="@+id/nextHUA"            android:layout_width="wrap_content"            android:layout_height="match_parent"            android:text="@string/nextHUA"            android:textColor="@color/colorSliteGray"            android:gravity="center"/>    </LinearLayout><!--底部菜单栏-->    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_marginTop="10dp"        android:layout_marginBottom="10dp"        android:orientation="horizontal"        android:layout_marginLeft="20dp"        android:layout_marginRight="20dp">        <LinearLayout        android:id="@+id/indexBtn"        android:layout_width="0dp"        android:layout_height="wrap_content"        android:layout_weight="1"        android:orientation="vertical">        <ImageView            android:layout_width="30dp"            android:layout_height="30dp"            android:src="@mipmap/menu_expanded_109"            android:layout_gravity="center"/>        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_gravity="center"            android:gravity="center"            android:textColor="@color/colorSliteGray"            android:text="@string/index"/>    </LinearLayout>        <LinearLayout            android:id="@+id/download_comic_Btn"            android:layout_width="0dp"            android:layout_height="wrap_content"            android:layout_weight="1"            android:orientation="vertical">            <ImageView                android:layout_width="30dp"                android:layout_height="30dp"                android:src="@mipmap/downloadbtn"                android:layout_gravity="center"/>            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:gravity="center"                android:layout_gravity="center"                android:textColor="@color/colorSliteGray"                android:text="@string/download"/>        </LinearLayout>        <LinearLayout        android:id="@+id/light_btn"        android:layout_width="0dp"        android:layout_height="wrap_content"        android:layout_weight="1"        android:orientation="vertical">        <ImageView            android:layout_width="30dp"            android:layout_height="30dp"            android:src="@mipmap/light_bulb_46"            android:layout_gravity="center"/>        <TextView            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:gravity="center"            android:layout_gravity="center"            android:textColor="@color/colorSliteGray"            android:text="@string/light"/>    </LinearLayout>        <LinearLayout            android:id="@+id/phone_switch"            android:layout_width="0dp"            android:layout_height="wrap_content"            android:layout_weight="1"            android:orientation="vertical">            <ImageView                android:layout_width="30dp"                android:layout_height="30dp"                android:src="@mipmap/phonestatus_switch"                android:layout_gravity="center"/>            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:gravity="center"                android:layout_gravity="center"                android:textColor="@color/colorSliteGray"                android:text="@string/landscape"/>        </LinearLayout>        <LinearLayout            android:id="@+id/options_btn"            android:layout_width="0dp"            android:layout_height="wrap_content"            android:layout_weight="1"            android:orientation="vertical">            <ImageView                android:layout_width="30dp"                android:layout_height="30dp"                android:src="@mipmap/options_72"                android:layout_gravity="center"/>            <TextView                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:gravity="center"                android:layout_gravity="center"                android:textColor="@color/colorSliteGray"                android:text="@string/options"/>        </LinearLayout>    </LinearLayout></LinearLayout></RelativeLayout>

RecyclerView item布局:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"              android:orientation="vertical"              android:layout_width="match_parent"              android:layout_height="match_parent"><RelativeLayout    android:layout_width="match_parent"    android:layout_weight="1"    android:layout_height="0dp">    <!--做出占位的字,图片加载出来后会被图片覆盖-->    <TextView        android:id="@+id/textView"        android:background="@color/colorSliteGray"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:textColor="@color/colorDimGray"        android:text="1"        android:textSize="80sp"        android:gravity="center"/>    <ImageView        android:id="@+id/imageView"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:scaleType="fitXY"        android:layout_gravity="center"/></RelativeLayout><!--分隔线,让布局看起来更清晰,可以去掉--><LinearLayout    android:layout_width="match_parent"    android:layout_height="3dp"    android:background="@color/colorSliteGray"    android:layout_alignParentBottom="true"></LinearLayout></LinearLayout>


控制代码:

package winter.zxb.smilesb101.cartoon8;import android.annotation.SuppressLint;import android.app.Activity;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.content.IntentFilter;import android.media.Image;import android.os.AsyncTask;import android.os.BatteryManager;import android.os.Message;import android.support.annotation.Nullable;import android.support.v4.app.Fragment;import android.support.v4.app.FragmentManager;import android.support.v4.app.FragmentPagerAdapter;import android.support.v7.app.ActionBar;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.os.Handler;import android.support.v7.widget.LinearLayoutManager;import android.support.v7.widget.RecyclerView;import android.util.Log;import android.view.LayoutInflater;import android.view.MotionEvent;import android.view.View;import android.view.ViewGroup;import android.view.WindowManager;import android.view.animation.Animation;import android.view.animation.TranslateAnimation;import android.widget.Button;import android.widget.ImageSwitcher;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.RelativeLayout;import android.widget.SeekBar;import android.widget.TextView;import android.widget.Toast;import com.bumptech.glide.Glide;import java.util.ArrayList;import ComicData.Comic;import RetailsWorm.HtmlAnalysisUtils;import RetailsWorm.NetWorkUtils;import Utils.Utils;import static ComicData.comicStaticValue.COMIC_PICS;import static ComicData.comicStaticValue.COMIC_PIC_DOM;/** * An example full-screen activity that shows and hides the system UI (i.e. * status bar and navigation/system bar) with user interaction. */public final class WatchComicActivity extends AppCompatActivity implements View.OnClickListener{/** * Whether or not the system UI should be auto-hidden after * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds. */private static final boolean AUTO_HIDE = true;/** * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after * user interaction before hiding the system UI. */private static final int AUTO_HIDE_DELAY_MILLIS = 1000;/** * 动画时间 */private static final int UI_ANIMATION_DELAY = 200;private final Handler mHideHandler = new Handler();private RecyclerView mContentView;private View mControlsView;private MyContentViewAdapter adapter;private int adapterNowPos,allItems;private final Runnable mShowPart2Runnable = new Runnable(){@Overridepublic void run(){// Delayed display of UI elementsActionBar actionBar = getSupportActionBar();if(actionBar != null) {actionBar.show();}}};/** * 显示或者隐藏状态 */private boolean mVisible;Handler handler = new Handler(){@Overridepublic void handleMessage(Message msg){switch(msg.what) {case NetWorkUtils.MSG_HTML:String html = msg.obj.toString();if(!html.equals(NetWorkUtils.HTML_EMPTY)) {InitLayoutValue(html);}else{Log.i(TAG,"handleMessage: 网络错误!!");}break;}}};/** * 处理网页 * @param html */void InitLayoutValue(final String html){new AsyncTask<String,Void,Void>(){@Overrideprotected Void doInBackground(String... params){Log.i(TAG,"doInBackground: 后台操作获取图片");comic = new Comic();comic_Pics = HtmlAnalysisUtils.getComicPicsString(params[0],COMIC_PICS,5);//第5个位置是图片位置comic.setName(HtmlAnalysisUtils.getComicDetails(params[0],COMIC_PIC_DOM.get(2),HtmlAnalysisUtils.WHAT_innerHTML).get(0));comic_hua = HtmlAnalysisUtils.getComicDetails(params[0],COMIC_PIC_DOM.get(1),HtmlAnalysisUtils.WHAT_innerHTML).get(0).replace(comic.getName(),"");//去掉多余的名称return null;}@Overrideprotected void onPostExecute(Void aVoid){super.onPostExecute(aVoid);//Log.i(TAG,"onPostExecute: 获取图片完成");comic_name_bottom.setText(comic_hua);comic_name_top.setText(comic_hua);if(comic_Pics!=null){Log.i(TAG,"onPostExecute: "+comic_Pics.get(1));//实例化adaptermContentView.setLayoutManager(new LinearLayoutManager(activity));adapter = new MyContentViewAdapter(comic_Pics);mContentView.setAdapter(adapter);mContentView.setOnScrollListener(scrollListener);}}}.execute(html);}private RecyclerView.OnScrollListener scrollListener = new RecyclerView.OnScrollListener(){@Overridepublic void onScrolled(RecyclerView recyclerView,int dx,int dy){super.onScrolled(recyclerView,dx,dy);LinearLayoutManager l = (LinearLayoutManager)recyclerView.getLayoutManager();adapterNowPos = l.findFirstVisibleItemPosition();allItems = l.getItemCount();//设置seekbarseekBar.setMax(allItems-1);Log.i(TAG,"onScrolled: "+allItems);seekBar.setProgress(adapterNowPos);setpicText();//设置文字}};private static final String TAG = "WatchComicActivity";/** * 漫画的VALUE */public static String COMIC_VALUE = "COMIC";public static String COMIC_LINK = "CMOIC_LINK";public static String COMIC_HUA = "HUA";public static String COMIC_NAME = "NAME";private Comic comic;private String comic_link;private String comic_hua;private ArrayList<String> comic_Pics;private Activity activity;private LinearLayout toplayout;private Button showCtrlbtn,backBtn,feedbackBtn,downLoadPicBtn,sharePicBtn;private LinearLayout bottomlayout;private TextView nextToogle,toogleBtn,preToogle;private LinearLayout menu_content;private TextView comic_name_bottom,comic_pic_state,time,battery;private SeekBar seekBar;private LinearLayout small_status;private RelativeLayout bottom_seekBar_help;private TextView seekBar_help_now,seekBar_help_num;private Button backbtn;private TextView comic_name_top,pic_state_top;private LinearLayout indexBtn,download_comic_Btn,light_btn,phone_switch,options_btn;@Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);setContentView(R.layout.activity_watch_comic);//注册电量监听广播registerReceiver(batterReceiver,new IntentFilter(Intent.ACTION_BATTERY_CHANGED));mVisible = false;//一开始是不可见状态mContentView = (RecyclerView)findViewById(R.id.fullscreen_content);toplayout = (LinearLayout)findViewById(R.id.top_layout);bottomlayout = (LinearLayout)findViewById(R.id.bottom_layout);toogleBtn = (TextView)findViewById(R.id.toogle);nextToogle = (TextView)findViewById(R.id.nextHUAText);preToogle = (TextView)findViewById(R.id.preHUAText);menu_content = (LinearLayout)findViewById(R.id.menu_content);showCtrlbtn = (Button)findViewById(R.id.show_menuBtn);backBtn = (Button)findViewById(R.id.back_btn);feedbackBtn = (Button)findViewById(R.id.feed_backBtn);downLoadPicBtn = (Button)findViewById(R.id.downloadpic_Btn);sharePicBtn = (Button)findViewById(R.id.sharePicBtn);bottom_seekBar_help = (RelativeLayout)findViewById(R.id.bottom_seekBar_help);seekBar_help_now = (TextView)findViewById(R.id.seekBar_help_now);seekBar_help_num = (TextView)findViewById(R.id.seekBar_help_num);menu_content.setOnClickListener(this);showCtrlbtn.setOnClickListener(this);backBtn.setOnClickListener(this);feedbackBtn.setOnClickListener(this);downLoadPicBtn.setOnClickListener(this);sharePicBtn.setOnClickListener(this);comic_name_bottom = (TextView)findViewById(R.id.comic_name_bottom);comic_pic_state = (TextView)findViewById(R.id.comic_pic_state);time = (TextView)findViewById(R.id.time);battery = (TextView)findViewById(R.id.battery);time.setText(Utils.getTimeHour());small_status = (LinearLayout)findViewById(R.id.small_status);seekBar = (SeekBar)findViewById(R.id.bottom_seekBar);seekBar.setOnSeekBarChangeListener(seekChangerListener);//Log.i(TAG,"onCreate: "+Utils.getPhoneBatteryInfo(this,BatteryManager.BATTERY_PROPERTY_CURRENT_NOW,Utils.DATATYPE_INT));toogleBtn.setOnClickListener(this);nextToogle.setOnClickListener(this);preToogle.setOnClickListener(this);toogleBtn.setOnTouchListener(ctrl_touchlistenner);nextToogle.setOnTouchListener(ctrl_touchlistenner);preToogle.setOnTouchListener(ctrl_touchlistenner);comic_name_top = (TextView)findViewById(R.id.comic_name);pic_state_top = (TextView)findViewById(R.id.comic_pic_state_top);//底边菜单indexBtn = (LinearLayout)findViewById(R.id.indexBtn);download_comic_Btn = (LinearLayout)findViewById(R.id.download_comic_Btn);light_btn = (LinearLayout)findViewById(R.id.light_btn);phone_switch = (LinearLayout)findViewById(R.id.phone_switch);options_btn  = (LinearLayout)findViewById(R.id.options_btn);indexBtn.setOnClickListener(this);download_comic_Btn.setOnClickListener(this);light_btn.setOnClickListener(this);phone_switch.setOnClickListener(this);indexBtn.setOnClickListener(this);options_btn.setOnClickListener(this);activity = this;if(getIntent()!=null){Intent intent = getIntent();comic = (Comic)intent.getSerializableExtra(COMIC_VALUE);comic_link = intent.getStringExtra(COMIC_LINK);new Runnable(){@Overridepublic void run(){NetWorkUtils.getHtmlPage(activity,comic_link,handler);//获取网页数据}}.run();}}private float Sy = 0,Ey = 0;//放在外面是为了更新sy的值,让滑动更加顺滑/** * 控制板的触摸事件监听,用来处理滑动冲突(控制面板与recyclerView的滑动冲突) */View.OnTouchListener ctrl_touchlistenner = new View.OnTouchListener(){@Overridepublic boolean onTouch(View v,MotionEvent event){switch(event.getAction()){case MotionEvent.ACTION_DOWN:Sy = event.getY();//Log.i(TAG,"onTouch: 按下事件 "+Sy);break;case MotionEvent.ACTION_MOVE:Ey = event.getY();float res = (Ey-Sy);//Log.i(TAG,"onTouch: 分发事件给recyclerView 移动距离为 "+res);//让RecyclerView开始滑动mContentView.scrollBy(mContentView.getScrollX(),mContentView.getScrollY()-(int)res);Sy = event.getY();//更新开始位置break;}return false;}};/** * seekBar值改变的监听 */SeekBar.OnSeekBarChangeListener seekChangerListener = new SeekBar.OnSeekBarChangeListener(){@Overridepublic void onProgressChanged(SeekBar seekBar,int progress,boolean fromUser){//更新辅助面板if(bottom_seekBar_help.getVisibility()==View.VISIBLE) {seekBar_help_now.setText(progress + 1+"");}}@Overridepublic void onStartTrackingTouch(SeekBar seekBar){            //显示辅助面板bottom_seekBar_help.setVisibility(View.VISIBLE);seekBar_help_num.setText(seekBar.getMax()+1+"");//设置总数}@Overridepublic void onStopTrackingTouch(SeekBar seekBar){//关闭辅助面板bottom_seekBar_help.setVisibility(View.GONE);int progress = seekBar.getProgress();Log.i(TAG,"onProgressChanged: 选择了,第"+progress);//设置图片状态(1/9);adapterNowPos = progress;setpicText();mContentView.scrollToPosition(adapterNowPos);//不能平稳滑动,否者联动出错}};/** * 设置图片文字(第几张/总共几张) */void setpicText(){String s = adapterNowPos+1+ "/" + allItems;comic_pic_state.setText(s);//设置图片的数量pic_state_top.setText(s);}/** * 展示上下栏 */void showPanel(){//Log.i(TAG,"hidePanel: 显示");TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0.0f,Animation.RELATIVE_TO_SELF,0.0f,Animation.RELATIVE_TO_SELF,1.0f,Animation.RELATIVE_TO_SELF,0.0f);TranslateAnimation translateAnimation1 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,-1.0f, Animation.RELATIVE_TO_SELF, 0.0f);translateAnimation.setDuration(UI_ANIMATION_DELAY);translateAnimation1.setDuration(UI_ANIMATION_DELAY);toplayout.setAnimation(translateAnimation1);bottomlayout.setAnimation(translateAnimation);toplayout.setVisibility(View.VISIBLE);//这里通过改变可见性来播放动画bottomlayout.setVisibility(View.VISIBLE);//这里通过改变可见性来播放动画//底部状态栏消失small_status.setVisibility(View.GONE);//隐藏上下操作板,注意只能是隐藏,不能GONE,否者会导致中间控制板占据所有屏幕的问题nextToogle.setVisibility(View.INVISIBLE);preToogle.setVisibility(View.INVISIBLE);}/** * 隐藏上下栏 */void hidePanel(){//Log.i(TAG,"hidePanel: 隐藏");TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,0.0f,Animation.RELATIVE_TO_SELF,0.0f,Animation.RELATIVE_TO_SELF,0.0f,Animation.RELATIVE_TO_SELF,-1.0f);TranslateAnimation translateAnimation1 = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,0.0f, Animation.RELATIVE_TO_SELF, 1.0f);translateAnimation.setDuration(UI_ANIMATION_DELAY);translateAnimation1.setDuration(UI_ANIMATION_DELAY);toplayout.setAnimation(translateAnimation);bottomlayout.setAnimation(translateAnimation1);toplayout.setVisibility(View.INVISIBLE);//这里通过改变可见性来播放动画bottomlayout.setVisibility(View.INVISIBLE);//这里通过改变可见性来播放动画//底部状态栏显示small_status.setVisibility(View.VISIBLE);//显示上下操作板nextToogle.setVisibility(View.VISIBLE);preToogle.setVisibility(View.VISIBLE);}/** * 触发器用来控制显示与隐藏 */void toogle(){if(mVisible){hidePanel();mVisible = false;}else{showPanel();mVisible = true;}}@Overridepublic void onClick(View v){switch(v.getId()){case R.id.back_btn://返回按钮onBackPressed();//调用返回break;case R.id.show_menuBtn://显示操作平台按钮//Log.i(TAG,"onClick: 操作平台按钮");if(View.GONE == menu_content.getVisibility()) {menu_content.setVisibility(View.VISIBLE);hidePanel();mVisible = false;//底部状态栏消失small_status.setVisibility(View.GONE);}break;case R.id.feed_backBtn://反馈按钮break;case R.id.downloadpic_Btn://下载此张图片按钮break;case R.id.sharePicBtn://分享漫画链接或者此张图片break;case R.id.toogle://Log.i(TAG,"onClick: 隐藏按钮按下");toogle();break;case R.id.nextHUAText://下一张图片adapterNowPos++;scroolRV_To(adapterNowPos);break;case R.id.preHUAText://上一张图片adapterNowPos--;scroolRV_To(adapterNowPos);break;case R.id.menu_content://操作面板容器menu_content.setVisibility(View.GONE);//底部状态栏显示small_status.setVisibility(View.GONE);break;case R.id.indexBtn://目录按钮//目录界面break;case R.id.download_comic_Btn://下载漫画按钮break;case R.id.light_btn://亮度按钮break;case R.id.phone_switch://切换手机的横竖屏break;case R.id.options_btn://选项按钮break;}}/** * 滚动到位置 * @param pos */void scroolRV_To(int pos){if(adapterNowPos>=allItems){adapterNowPos = allItems;Toast.makeText(this,"已经到顶啦!",Toast.LENGTH_SHORT);}else if(adapterNowPos <= 0){adapterNowPos = 0;Toast.makeText(this,"已经到底啦!",Toast.LENGTH_SHORT);}mContentView.smoothScrollToPosition(adapterNowPos);}/** * 图片显示view的adapter */class MyContentViewAdapter extends RecyclerView.Adapter{private ArrayList<String> pics;private Context context;public MyContentViewAdapter(ArrayList<String> pics){this.pics = pics;}@Overridepublic RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,int viewType){context = parent.getContext();View view = LayoutInflater.from(context).inflate(R.layout.comicpics_item,parent,false);return new MyViewHolder(view);}@Overridepublic void onBindViewHolder(RecyclerView.ViewHolder holder,int position){MyViewHolder myViewHolder = (MyViewHolder)holder;myViewHolder.textView.setText(position+1+"");//设置占位Glide.with(context).load(pics.get(position)).into(myViewHolder.imageView);}@Overridepublic int getItemCount(){return pics.size();}class MyViewHolder extends RecyclerView.ViewHolder{private View rootView;private ImageView imageView;private TextView textView;public MyViewHolder(View itemView){super(itemView);rootView = itemView;imageView = (ImageView)rootView.findViewById(R.id.imageView);textView = (TextView)rootView.findViewById(R.id.textView);}}}public BroadcastReceiver batterReceiver  = new BroadcastReceiver(){@Overridepublic void onReceive(Context context,Intent intent){int level = intent.getIntExtra("level",0);//Log.i(TAG,"onReceive: "+level);battery.setText(level+"%");}};}





0 0
原创粉丝点击