-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
新增 1.新增查看文章内的所有图片,左右滑动可切换 2.图片可放大缩小
- Loading branch information
Showing
19 changed files
with
1,645 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
app/src/main/java/com/zhongzilu/bit100/application/receiver/NetworkBroadcastReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.zhongzilu.bit100.application.receiver; | ||
|
||
import android.content.BroadcastReceiver; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.net.ConnectivityManager; | ||
import android.net.NetworkInfo; | ||
|
||
/** | ||
* 监听网络状态变化的广播接收器 | ||
* Created by zhongzilu on 2016-10-24. | ||
*/ | ||
public class NetworkBroadcastReceiver extends BroadcastReceiver { | ||
private static final String TAG = "NetworkBroadcastReceiver==>"; | ||
|
||
@Override | ||
public void onReceive(Context context, Intent intent) { | ||
//获取手机的连接服务管理器,这里是连接管理器类 | ||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); | ||
|
||
// if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||
// Network[] states = cm.getAllNetworks(); | ||
// | ||
// if (states != null){ | ||
// for (Network work : states){ | ||
// NetworkInfo networkInfo = cm.getNetworkInfo(work); | ||
// | ||
// if (networkInfo.getType() == ConnectivityManager.TYPE_WIFI && | ||
// networkInfo.getState().equals(NetworkInfo.State.CONNECTED )){ | ||
// | ||
// return; | ||
// } | ||
// } | ||
// | ||
// //wifi和数据流量都没有打开,提示没有可用网络,引导用户打开任意网络 | ||
// } | ||
// | ||
// return; | ||
// } | ||
|
||
NetworkInfo.State wifiState = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState(); | ||
NetworkInfo.State mobileState = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState(); | ||
NetworkInfo.State mobile4G = cm.getNetworkInfo(ConnectivityManager.TYPE_WIMAX).getState(); | ||
|
||
if (wifiState == null && mobileState == null){ | ||
//wifi和数据流量都没有打开,提示没有可用网络,引导用户打开任意网络 | ||
return; | ||
} | ||
|
||
if (NetworkInfo.State.CONNECTED == wifiState){ | ||
//wifi连接可用,这时可以加载比较耗流量的内容,比如更高清的图片和视频等 | ||
return; | ||
} | ||
|
||
if (NetworkInfo.State.CONNECTED == mobile4G){ | ||
//4G网络可用,这时可以加载比较耗流量的内容,同时也通过缓存机制和其他机制 | ||
//优化网络请求频率以及数据加载以减少流量消耗 | ||
return; | ||
} | ||
|
||
if (NetworkInfo.State.CONNECTED == mobileState){ | ||
//数据流量可用,这时避免加载比较耗流量的内容,同时,可以通过缓存机制和其他机制 | ||
//优化网络请求频率以及数据加载以减少流量消耗 | ||
// return; | ||
} | ||
|
||
} | ||
} |
176 changes: 176 additions & 0 deletions
176
app/src/main/java/com/zhongzilu/bit100/view/activity/GalleryActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
package com.zhongzilu.bit100.view.activity; | ||
|
||
import android.content.Intent; | ||
import android.os.Bundle; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v4.app.FragmentManager; | ||
import android.support.v4.app.FragmentPagerAdapter; | ||
import android.support.v4.view.ViewPager; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.LayoutInflater; | ||
import android.view.Menu; | ||
import android.view.MenuItem; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.bumptech.glide.Glide; | ||
import com.zhongzilu.bit100.R; | ||
import com.zhongzilu.bit100.application.util.LogUtil; | ||
import com.zhongzilu.bit100.widget.TouchImageView; | ||
|
||
/** | ||
* 图片画廊,用于查看网页上的图片 | ||
* Created by zhongzilu on 2016-09-16. | ||
*/ | ||
public class GalleryActivity extends AppCompatActivity { | ||
private static final String TAG = "GalleryActivity==>"; | ||
|
||
//Extra Tag | ||
public static final String EXTRA_IMAGES_LIST = "images_list"; | ||
public static final String EXTRA_CURRENT_IMAGE_POSITION = "image_position"; | ||
|
||
//Extra Value | ||
private String[] mList; | ||
private int mChosePosition; | ||
|
||
/** | ||
* The {@link android.support.v4.view.PagerAdapter} that will provide | ||
* fragments for each of the sections. We use a | ||
* {@link FragmentPagerAdapter} derivative, which will keep every | ||
* loaded fragment in memory. If this becomes too memory intensive, it | ||
* may be best to switch to a | ||
* {@link android.support.v4.app.FragmentStatePagerAdapter}. | ||
*/ | ||
private SectionsPagerAdapter mSectionsPagerAdapter; | ||
|
||
/** | ||
* The {@link ViewPager} that will host the section contents. | ||
*/ | ||
private ViewPager mViewPager; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_gallery); | ||
|
||
mViewPager = (ViewPager) findViewById(R.id.container); | ||
|
||
Intent intent = getIntent(); | ||
if (intent != null){ | ||
mList = intent.getStringArrayExtra(EXTRA_IMAGES_LIST); | ||
mChosePosition = intent.getIntExtra(EXTRA_CURRENT_IMAGE_POSITION, 0); | ||
} | ||
|
||
// 如果mList为空,则不再进行其他操作 | ||
if (mList == null) { | ||
LogUtil.d(TAG, "onCreate: mList is null"); | ||
return; | ||
} | ||
// Create the adapter that will return a fragment for each of the three | ||
// primary sections of the activity. | ||
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(), mList); | ||
mViewPager.setOffscreenPageLimit(2); | ||
// Set up the ViewPager with the sections adapter. | ||
mViewPager.setAdapter(mSectionsPagerAdapter); | ||
mViewPager.setCurrentItem(mChosePosition, true); | ||
} | ||
|
||
|
||
@Override | ||
public boolean onCreateOptionsMenu(Menu menu) { | ||
// Inflate the menu; this adds items to the action bar if it is present. | ||
getMenuInflater().inflate(R.menu.menu_gallery, menu); | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean onOptionsItemSelected(MenuItem item) { | ||
switch (item.getItemId()){ | ||
case R.id.action_settings: | ||
|
||
break; | ||
} | ||
|
||
return super.onOptionsItemSelected(item); | ||
} | ||
|
||
/** | ||
* A placeholder fragment containing a simple view. | ||
*/ | ||
public static class PlaceholderFragment extends Fragment { | ||
private static final String TAG = "PlaceholderFragment==>"; | ||
/** | ||
* The fragment argument representing the section number for this | ||
* fragment. | ||
*/ | ||
private static final String ARG_IMAGE_URL = "image_url"; | ||
private View contentView; | ||
|
||
public PlaceholderFragment() {} | ||
|
||
/** | ||
* Returns a new instance of this fragment for the given section | ||
* number. | ||
*/ | ||
public static PlaceholderFragment newInstance(String url) { | ||
PlaceholderFragment fragment = new PlaceholderFragment(); | ||
Bundle args = new Bundle(); | ||
args.putString(ARG_IMAGE_URL, url); | ||
fragment.setArguments(args); | ||
return fragment; | ||
} | ||
|
||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
if (contentView == null) | ||
contentView = inflater.inflate(R.layout.fragment_gallery, container, false); | ||
return contentView; | ||
} | ||
|
||
@Override | ||
public void onViewCreated(View view, Bundle savedInstanceState) { | ||
super.onViewCreated(view, savedInstanceState); | ||
|
||
TouchImageView imageView = (TouchImageView) view.findViewById(R.id.img_touch_image); | ||
String url = getArguments().getString(ARG_IMAGE_URL); | ||
LogUtil.d(TAG, "onViewCreated: url==>" + url); | ||
Glide.with(getContext()) | ||
.load(url) | ||
.placeholder(R.drawable.image_default) | ||
.error(R.drawable.image_default) | ||
.into(imageView); | ||
} | ||
} | ||
|
||
/** | ||
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to | ||
* one of the sections/tabs/pages. | ||
*/ | ||
public class SectionsPagerAdapter extends FragmentPagerAdapter { | ||
private String[] imgSrc; | ||
|
||
public SectionsPagerAdapter(FragmentManager fm, String[] imgS) { | ||
super(fm); | ||
this.imgSrc = imgS; | ||
} | ||
|
||
@Override | ||
public Fragment getItem(int position) { | ||
// getItem is called to instantiate the fragment for the given page. | ||
// Return a PlaceholderFragment (defined as a static inner class below). | ||
return PlaceholderFragment.newInstance(imgSrc[position]); | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
// Show imgSrc length total pages. | ||
return imgSrc.length; | ||
} | ||
|
||
@Override | ||
public CharSequence getPageTitle(int position) { | ||
return ""; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.