Sfoglia il codice sorgente

new commit

Signed-off-by: 1145873331@qq.com <dnfdnf666>
1145873331@qq.com 6 anni fa
parent
commit
d98f3c34c5
60 ha cambiato i file con 4904 aggiunte e 600 eliminazioni
  1. BIN
      .DS_Store
  2. 21 0
      app/bugly/BuglyUploadLog.txt
  3. 1 1
      app/build.gradle
  4. BIN
      app/libs/AMap3DMap_3.3.3_AMapNavi_1.9.1_20160726.jar
  5. BIN
      app/libs/AMap3DMap_4.1.3_AMapNavi_1.9.4_AMapSearch_4.0.0_AMapLocation_3.3.0_20170118.jar
  6. BIN
      app/libs/AMapNavi_1.9.4_AMapLocation_3.1.0_20161201.jar
  7. BIN
      app/libs/AMap_Location_V2.4.1_20160414.jar
  8. BIN
      app/libs/AMap_Search_V3.2.1_20160308.jar
  9. BIN
      app/libs/Android_Map3D_SDK_V4.1.3_20161208.jar
  10. 9 9
      app/src/main/AndroidManifest.xml
  11. 117 126
      app/src/main/java/com/electric/chargingpile/activity/MainMapActivity.java
  12. 1 1
      app/src/main/java/com/electric/chargingpile/activity/QaActivity.java
  13. 7 4
      app/src/main/java/com/electric/chargingpile/activity/TalkActivity.java
  14. 1 3
      app/src/main/java/com/electric/chargingpile/activity/UnansweredActivity.java
  15. 123 0
      app/src/main/java/com/electric/chargingpile/activity/VideoDetaislActivity.java
  16. 0 11
      app/src/main/java/com/electric/chargingpile/activity/WelcomeActivity.java
  17. 12 12
      app/src/main/java/com/electric/chargingpile/activity/ZoomingPhotoTextActivity.java
  18. 37 18
      app/src/main/java/com/electric/chargingpile/adapter/LayoutAdapter.java
  19. 100 0
      app/src/main/java/com/electric/chargingpile/adapter/SvVideoPagerAdapter.java
  20. 119 0
      app/src/main/java/com/electric/chargingpile/adapter/VideoCommentAdapter.java
  21. 3 7
      app/src/main/java/com/electric/chargingpile/data/CommentsBean.java
  22. 24 1
      app/src/main/java/com/electric/chargingpile/data/TalkRecommendBean.java
  23. 180 0
      app/src/main/java/com/electric/chargingpile/data/VideoCommentBean.java
  24. 37 0
      app/src/main/java/com/electric/chargingpile/data/VideoDetailsBean.java
  25. 0 15
      app/src/main/java/com/electric/chargingpile/fragment/QaActivityFragment.java
  26. 0 3
      app/src/main/java/com/electric/chargingpile/fragment/QaZanFragment.java
  27. 107 0
      app/src/main/java/com/electric/chargingpile/fragment/ShortVideoFragment.java
  28. 186 0
      app/src/main/java/com/electric/chargingpile/fragment/SvVideoShowView.java
  29. 68 43
      app/src/main/java/com/electric/chargingpile/fragment/TalkRecommendFragment.java
  30. 2 0
      app/src/main/java/com/electric/chargingpile/iview/RecyclerItemTypeClickListener.java
  31. 0 41
      app/src/main/java/com/electric/chargingpile/view/AutoHeightViewPager.java
  32. 0 80
      app/src/main/java/com/electric/chargingpile/view/AutoSplitTextView.java
  33. 0 216
      app/src/main/java/com/electric/chargingpile/view/Dialog.java
  34. 194 0
      app/src/main/java/com/electric/chargingpile/view/VideoCommentDialog.java
  35. 66 0
      app/src/main/java/com/electric/chargingpile/view/VideoPubilshDialog.java
  36. 28 0
      app/src/main/java/com/electric/chargingpile/view/sview/SvHomeViewPager.java
  37. 2791 0
      app/src/main/java/com/electric/chargingpile/view/sview/VerticalViewPager.java
  38. 7 0
      app/src/main/res/anim/bottom_in_anim.xml
  39. 7 0
      app/src/main/res/anim/bottom_out_anim.xml
  40. 0 0
      app/src/main/res/drawable-xxhdpi/mima.png
  41. 0 0
      app/src/main/res/drawable-xxhdpi/rentou.png
  42. 0 0
      app/src/main/res/drawable-xxhdpi/shanche.png
  43. 0 0
      app/src/main/res/drawable-xxhdpi/top.png
  44. 0 0
      app/src/main/res/drawable-xxhdpi/tubiao1.png
  45. 0 0
      app/src/main/res/drawable-xxhdpi/zhuangtailan.png
  46. 0 0
      app/src/main/res/drawable-xxhdpi/zhucaozuolan.png
  47. 12 0
      app/src/main/res/drawable/bg_bottom_dialog.xml
  48. 10 0
      app/src/main/res/drawable/bg_comment_report.xml
  49. 10 0
      app/src/main/res/drawable/bg_topic.xml
  50. 48 0
      app/src/main/res/layout/activity_videodetails.xml
  51. 11 0
      app/src/main/res/layout/fragment_shortvideo.xml
  52. 130 0
      app/src/main/res/layout/item_show_comment.xml
  53. 85 0
      app/src/main/res/layout/sv_video_publish_info.xml
  54. 204 0
      app/src/main/res/layout/view_show_bottom.xml
  55. 74 0
      app/src/main/res/layout/view_show_comment.xml
  56. 13 0
      app/src/main/res/layout/view_show_view.xml
  57. 15 0
      app/src/main/res/layout/view_show_zoom.xml
  58. 2 0
      app/src/main/res/values/color.xml
  59. 12 0
      app/src/main/res/values/strings.xml
  60. 30 9
      app/src/main/res/values/styles.xml

BIN
.DS_Store


+ 21 - 0
app/bugly/BuglyUploadLog.txt

@ -5,3 +5,24 @@ appChannel=anzhi
5 5
appPackage=com.electric.chargingpile
6 6
appVersion=3.2.1
7 7
8
file=C:\Development Projects\Android_project\android_chargingpile\app\build\outputs\mapping\anzhi\debug\mapping.txt
9
sha1=ddf1583852d1f90c2e0505c203a0fd665221b477
10
appId=900010422
11
appChannel=anzhi
12
appPackage=com.electric.chargingpile
13
appVersion=3.2.1
14
15
file=C:\Development Projects\Android_project\android_chargingpile\app\build\outputs\mapping\anzhi\debug\mapping.txt
16
sha1=3db22ee78ad3f2135a2b616dbcaf50920ae8c820
17
appId=900010422
18
appChannel=anzhi
19
appPackage=com.electric.chargingpile
20
appVersion=3.2.1
21
22
file=C:\Development Projects\Android_project\android_chargingpile\app\build\outputs\mapping\anzhi\debug\mapping.txt
23
sha1=e42e3780171cd84d117516c642887701399f45d2
24
appId=900010422
25
appChannel=anzhi
26
appPackage=com.electric.chargingpile
27
appVersion=3.2.1
28

+ 1 - 1
app/build.gradle

@ -313,7 +313,7 @@ dependencies {
313 313
314 314
    //    compile 'com.github.vilyever:AndroidSocketClient:3.0.3'
315 315
    compile files('libs/AMap3DMap_6.5.0_AMapNavi_6.4.0_AMapSearch_6.5.0_AMapLocation_4.2.0_20181009.jar')
316
    compile 'com.qmuiteam:qmui:1.1.5'
316
    compile 'com.qmuiteam:qmui:1.2.0'
317 317
    compile 'org.zackratos:ultimatebar:1.1.1'
318 318
    compile project(':XRefreshView')
319 319
    compile 'com.github.Aspsine:IRecyclerView:0.0.7'

BIN
app/libs/AMap3DMap_3.3.3_AMapNavi_1.9.1_20160726.jar


BIN
app/libs/AMap3DMap_4.1.3_AMapNavi_1.9.4_AMapSearch_4.0.0_AMapLocation_3.3.0_20170118.jar


BIN
app/libs/AMapNavi_1.9.4_AMapLocation_3.1.0_20161201.jar


BIN
app/libs/AMap_Location_V2.4.1_20160414.jar


BIN
app/libs/AMap_Search_V3.2.1_20160308.jar


BIN
app/libs/Android_Map3D_SDK_V4.1.3_20161208.jar


+ 9 - 9
app/src/main/AndroidManifest.xml

@ -1,12 +1,8 @@
1 1
<?xml version="1.0" encoding="utf-8"?>
2 2
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
    xmlns:tools="http://schemas.android.com/tools"
4 3
    package="com.electric.chargingpile"
5 4
    android:versionCode="73"
6
    android:versionName="3.2.1"> <!-- 3.1.5versionCode="61"  3.2.1versionCode=73-->
7
    <uses-sdk
8
        android:minSdkVersion="15"
9
        android:targetSdkVersion="26" />
5
    android:versionName="3.2.1">
10 6
11 7
    <!-- 极光 -->
12 8
    <permission
@ -59,7 +55,6 @@
59 55
    <!-- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> -->
60 56
    <!-- <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> -->
61 57
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
62
63 58
    <!-- 极光 -->
64 59
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
65 60
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
@ -766,7 +761,7 @@
766 761
        <activity
767 762
            android:name=".activity.RoutePlanMapActivity"
768 763
            android:screenOrientation="portrait"
769
            android:theme="@style/AppTheme"/>
764
            android:theme="@style/AppTheme" />
770 765
        <activity
771 766
            android:name=".activity.RoutePlanSelectAddressActivity"
772 767
            android:screenOrientation="portrait" />
@ -988,8 +983,13 @@
988 983
            android:name=".activity.NewSelectCityActivity"
989 984
            android:screenOrientation="portrait"
990 985
            android:windowSoftInputMode="adjustPan" />
991
        <activity android:name=".activity.SelectPileActivity"
992
            android:screenOrientation="portrait"></activity>
986
        <activity
987
            android:name=".activity.SelectPileActivity"
988
            android:screenOrientation="portrait" />
989
        <activity
990
            android:name=".activity.VideoDetaislActivity"
991
            android:screenOrientation="portrait"
992
            android:windowSoftInputMode="adjustPan" />
993 993
    </application>
994 994
995 995
</manifest>

+ 117 - 126
app/src/main/java/com/electric/chargingpile/activity/MainMapActivity.java

@ -28,7 +28,6 @@ import android.os.Message;
28 28
import android.support.annotation.NonNull;
29 29
import android.support.v4.app.ActivityCompat;
30 30
import android.support.v4.content.FileProvider;
31
import android.support.v7.app.AlertDialog;
32 31
import android.telephony.TelephonyManager;
33 32
import android.text.TextUtils;
34 33
import android.util.Log;
@ -81,7 +80,6 @@ import com.amap.api.services.weather.WeatherSearch;
81 80
import com.amap.api.services.weather.WeatherSearchQuery;
82 81
import com.blankj.utilcode.util.ActivityUtils;
83 82
import com.blankj.utilcode.util.AppUtils;
84
import com.blankj.utilcode.util.BarUtils;
85 83
import com.blankj.utilcode.util.EmptyUtils;
86 84
import com.blankj.utilcode.util.LogUtils;
87 85
import com.electric.chargingpile.R;
@ -106,9 +104,7 @@ import com.electric.chargingpile.data.zhan_list;
106 104
import com.electric.chargingpile.gen.DaoMaster;
107 105
import com.electric.chargingpile.gen.DaoSession;
108 106
import com.electric.chargingpile.gen.zhan_listDao;
109
import com.electric.chargingpile.helper.MyOpenHelper;
110 107
import com.electric.chargingpile.manager.ProfileManager;
111
import com.electric.chargingpile.util.ActivityManagerApplication;
112 108
import com.electric.chargingpile.util.BarColorUtil;
113 109
import com.electric.chargingpile.util.DES3;
114 110
import com.electric.chargingpile.util.DES3S;
@ -126,7 +122,6 @@ import com.electric.chargingpile.view.SlideAdView;
126 122
import com.electric.chargingpile.view.UpdateDialog;
127 123
import com.google.gson.Gson;
128 124
import com.google.gson.reflect.TypeToken;
129
130 125
import com.google.zxing.client.android.constant.ChargingConstants;
131 126
import com.qmuiteam.qmui.widget.dialog.QMUIBottomSheet;
132 127
import com.squareup.okhttp.Request;
@ -166,7 +161,6 @@ import java.util.Random;
166 161
import cn.sharesdk.framework.Platform;
167 162
import cn.sharesdk.framework.PlatformActionListener;
168 163
import cn.sharesdk.framework.ShareSDK;
169
import cn.sharesdk.onekeyshare.OnekeyShare;
170 164
import cn.sharesdk.tencent.qq.QQ;
171 165
import cn.sharesdk.wechat.friends.Wechat;
172 166
import cn.sharesdk.wechat.moments.WechatMoments;
@ -177,7 +171,7 @@ import pub.devrel.easypermissions.EasyPermissions;
177 171
178 172
public class MainMapActivity extends Activity implements LocationSource, AMapLocationListener,
179 173
        View.OnClickListener, AMap.OnMapLoadedListener, AMap.OnCameraChangeListener, AMap.OnMapClickListener,
180
        ClusterRender, ClusterClickListener, WeatherSearch.OnWeatherSearchListener ,EasyPermissions.PermissionCallbacks{
174
        ClusterRender, ClusterClickListener, WeatherSearch.OnWeatherSearchListener, EasyPermissions.PermissionCallbacks {
181 175
    private static final String TAG = "MainMapActivity";
182 176
    public static String screen_jing = "", screen_wei = "";
183 177
    public static String location_city = "";
@ -212,7 +206,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
212 206
    private Marker detailMarker;
213 207
    public static boolean onResumeRefresh = false;
214 208
    public static boolean search_back = false;
215
    private ImageView iv_guzhang,ivIsCost,iVpoint;
209
    private ImageView iv_guzhang, ivIsCost, iVpoint;
216 210
217 211
    private boolean clickMarker = false;
218 212
    public static LatLng center = null;
@ -318,7 +312,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
318 312
    public static TextView tv_atCity;
319 313
    public static RelativeLayout paoRl;
320 314
    public static LinearLayout rl_control;
321
    private RelativeLayout rela, ll_comment, rl_ad, rl_grade, rl_search, ll_paoxiang,rl_charging_notice;
315
    private RelativeLayout rela, ll_comment, rl_ad, rl_grade, rl_search, ll_paoxiang, rl_charging_notice;
322 316
    private RelativeLayout tv_notice, tv_citynotice, rl_mapList, ll_tab_find;
323 317
    private LinearLayout ll_paogo, ll_title, ll_open, tab_me, tab_screen;
324 318
    public static LinearLayout ll_tuijian, ll_top_right;
@ -382,7 +376,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
382 376
                    String s = f.substring(0, f.indexOf("."));
383 377
                    LogUtils.e(s);
384 378
385
                    updateDialog.updateMsg("当前已下载:"+format);
379
                    updateDialog.updateMsg("当前已下载:" + format);
386 380
                    updateDialog.updateProgress(Integer.parseInt(s));
387 381
388 382
                    break;
@ -1145,12 +1139,12 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1145 1139
        File databasePath = getDatabasePath("zhan_list");
1146 1140
        if (databasePath.exists()) {
1147 1141
            LogUtils.e("存在");
1148
                    eteinit("{\"fun\":\"timer\"}");
1149
                    try {
1150
                        getZhanData();
1151
                    } catch (Exception e) {
1152
                        e.printStackTrace();
1153
                    }
1142
            eteinit("{\"fun\":\"timer\"}");
1143
            try {
1144
                getZhanData();
1145
            } catch (Exception e) {
1146
                e.printStackTrace();
1147
            }
1154 1148
        } else {
1155 1149
            LogUtils.e("不存在");
1156 1150
            try {
@ -1160,8 +1154,8 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1160 1154
            }
1161 1155
        }
1162 1156
        showUi(MainApplication.isMap);
1163
        if(MainApplication.haveActivity== true){
1164
            List<Adin> listAdin = JsonUtils.parseToObjectList("["+MainApplication.ad_major+"]", Adin.class);
1157
        if (MainApplication.haveActivity == true) {
1158
            List<Adin> listAdin = JsonUtils.parseToObjectList("[" + MainApplication.ad_major + "]", Adin.class);
1165 1159
//            System.out.print("size:" + listAdin.size());
1166 1160
            if (listAdin.size() > 0) {
1167 1161
                sav.initData(listAdin);
@ -1435,21 +1429,20 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1435 1429
        ll_title = (LinearLayout) findViewById(R.id.ll_title);
1436 1430
1437 1431
1438
            if (aMap == null) {
1439
                aMap = mapView.getMap();
1440
1441
                maxZoomLevel = aMap.getMaxZoomLevel();
1442
                minZoomLevel = aMap.getMinZoomLevel();
1443
                MyLocationStyle myLocationStyle = new MyLocationStyle();
1444
                myLocationStyle.myLocationIcon(BitmapDescriptorFactory
1445
                        .fromResource(R.drawable.point_icon));// 设置小蓝点的图标
1446
                myLocationStyle.strokeColor(getResources().getColor(R.color.transparent));
1447
                myLocationStyle.radiusFillColor(getResources().getColor(R.color.transparent));
1448
                aMap.setMyLocationStyle(myLocationStyle);
1449
                mUiSettings = aMap.getUiSettings();
1450
                setUpMap();
1451
            }
1432
        if (aMap == null) {
1433
            aMap = mapView.getMap();
1452 1434
1435
            maxZoomLevel = aMap.getMaxZoomLevel();
1436
            minZoomLevel = aMap.getMinZoomLevel();
1437
            MyLocationStyle myLocationStyle = new MyLocationStyle();
1438
            myLocationStyle.myLocationIcon(BitmapDescriptorFactory
1439
                    .fromResource(R.drawable.point_icon));// 设置小蓝点的图标
1440
            myLocationStyle.strokeColor(getResources().getColor(R.color.transparent));
1441
            myLocationStyle.radiusFillColor(getResources().getColor(R.color.transparent));
1442
            aMap.setMyLocationStyle(myLocationStyle);
1443
            mUiSettings = aMap.getUiSettings();
1444
            setUpMap();
1445
        }
1453 1446
1454 1447
1455 1448
        iv_find = (ImageView) findViewById(R.id.iv_find);
@ -1507,16 +1500,16 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1507 1500
    @Override
1508 1501
    protected void onResume() {
1509 1502
        super.onResume();
1510
        if (FindActivity.haveFindMessage == true){
1503
        if (FindActivity.haveFindMessage == true) {
1511 1504
            iVpoint.setVisibility(View.VISIBLE);
1512
        }else {
1505
        } else {
1513 1506
            iVpoint.setVisibility(View.GONE);
1514 1507
        }
1515 1508
        saveTask();
1516 1509
        if (MainApplication.haveActivity == false) {
1517 1510
            if (MainApplication.isLogin() && MainApplication.isAppStart == true) {
1518 1511
                userChargingCheck();
1519
            }else {
1512
            } else {
1520 1513
                rl_charging_notice.setVisibility(View.GONE);
1521 1514
            }
1522 1515
@ -1692,8 +1685,8 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1692 1685
                    TelephonyManager telephonyManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
1693 1686
                    String imei;
1694 1687
                    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
1695
                        imei ="";
1696
                    }else {
1688
                        imei = "";
1689
                    } else {
1697 1690
                        imei = telephonyManager.getDeviceId();
1698 1691
                    }
1699 1692
//                Log.e("IMEI===", imei);
@ -1746,7 +1739,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1746 1739
    public static void controlZoomShow() {
1747 1740
        if (aMap != null) {
1748 1741
            float zoom = aMap.getCameraPosition().zoom;
1749
            Log.e(TAG, "controlZoomShow: "+zoom );
1742
            Log.e(TAG, "controlZoomShow: " + zoom);
1750 1743
            try {
1751 1744
                if (zoom >= maxZoomLevel) {
1752 1745
                    inBtn.setImageResource(R.drawable.icon_zoom_in_no);
@ -1803,7 +1796,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1803 1796
                    MainApplication.uptime = ProfileManager.getInstance().getDataUptime(getApplicationContext());
1804 1797
                    LogUtils.e(MainApplication.uptime);
1805 1798
1806
                    newUpdataZhanData(Token,MainApplication.uptime);
1799
                    newUpdataZhanData(Token, MainApplication.uptime);
1807 1800
                } catch (Exception e) {
1808 1801
                }
1809 1802
            }
@ -1811,11 +1804,11 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1811 1804
1812 1805
    }
1813 1806
1814
    private void newUpdataZhanData(String token ,String uptime){
1815
        String url = MainApplication.url+":9080/update_db";
1807
    private void newUpdataZhanData(String token, String uptime) {
1808
        String url = MainApplication.url + ":9080/update_db";
1816 1809
        OkHttpUtils.get().url(url)
1817
                .addParams("timer",token)
1818
                .addParams("uptime",uptime)
1810
                .addParams("timer", token)
1811
                .addParams("uptime", uptime)
1819 1812
                .build().execute(new StringCallback() {
1820 1813
            @Override
1821 1814
            public void onError(Call call, Exception e) {
@ -1825,9 +1818,9 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1825 1818
            @Override
1826 1819
            public void onResponse(String response) {
1827 1820
//                LogUtils.e(response);
1828
                String rtnCode = JsonUtils.getKeyResult(response,"rtnCode");
1829
                if ("0".equals(rtnCode)){
1830
                    String data = JsonUtils.getKeyResult(response,"data");
1821
                String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
1822
                if ("0".equals(rtnCode)) {
1823
                    String data = JsonUtils.getKeyResult(response, "data");
1831 1824
                    if (EmptyUtils.isNotEmpty(data)) {
1832 1825
                        final List<UpdateZhanDataBean> list = JsonUtils.parseToObjectList(data, UpdateZhanDataBean.class);
1833 1826
                        if (list.size() > 0) {
@ -1845,7 +1838,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1845 1838
        });
1846 1839
    }
1847 1840
1848
    private void dealUpdateData(List<UpdateZhanDataBean>list){
1841
    private void dealUpdateData(List<UpdateZhanDataBean> list) {
1849 1842
//        LogUtils.e(list.size());
1850 1843
        String dbPath = "/data/user/0/com.electric.chargingpile/databases/zhan_list";
1851 1844
        try {
@ -1871,7 +1864,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
1871 1864
1872 1865
                    long mub = db.replace("zhan_list", null, cv);
1873 1866
                    if (mub > 0) {
1874
                        ProfileManager.getInstance().setDataUptime(getApplicationContext(),bean.getUptime());
1867
                        ProfileManager.getInstance().setDataUptime(getApplicationContext(), bean.getUptime());
1875 1868
//                        LogUtils.e("添加成功"+ProfileManager.getInstance().getDataUptime(getApplicationContext()));
1876 1869
                    } else {
1877 1870
//                        LogUtils.e( "添加失败---" + bean.getId());
@ -2795,10 +2788,10 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
2795 2788
                    wei = String.valueOf(MainApplication.search_wei);
2796 2789
                } else {
2797 2790
                    Log.e(TAG, "onClick: 当前位置");
2798
                    if (null == center){
2799
                        ToastUtil.showToast(getApplicationContext(),"请确认当前定位是否可用",Toast.LENGTH_SHORT);
2791
                    if (null == center) {
2792
                        ToastUtil.showToast(getApplicationContext(), "请确认当前定位是否可用", Toast.LENGTH_SHORT);
2800 2793
                        break;
2801
                    }else {
2794
                    } else {
2802 2795
                        jing = String.valueOf(center.longitude);
2803 2796
                        wei = String.valueOf(center.latitude);
2804 2797
                    }
@ -2833,14 +2826,14 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
2833 2826
            case R.id.tv_person:
2834 2827
                windowLayout.setVisibility(View.GONE);
2835 2828
                rl_control.setVisibility(View.VISIBLE);
2836
                if (nMarker!= null){
2829
                if (nMarker != null) {
2837 2830
                    MarkerOptions markerOptionss = new MarkerOptions();
2838
                    if (current_chargePoint.getOwn_pay().equals("1")){
2831
                    if (current_chargePoint.getOwn_pay().equals("1")) {
2839 2832
                        nMarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.icon_newmarker1));
2840
                    }else {
2841
                        if (current_chargePoint.getSuit_car().equals("特斯拉")){
2833
                    } else {
2834
                        if (current_chargePoint.getSuit_car().equals("特斯拉")) {
2842 2835
                            nMarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.icon_newmarker3));
2843
                        }else {
2836
                        } else {
2844 2837
                            if (WelcomeActivity.canCost.contains(current_chargePoint.getSupplier())) {
2845 2838
                                nMarker.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.icon_newmarker2));
2846 2839
                            } else {
@ -2879,7 +2872,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
2879 2872
                    resetMarker();
2880 2873
                }
2881 2874
                MobclickAgent.onEvent(getApplicationContext(), "0107");
2882
                startActivity(new Intent(getApplicationContext(),NewSelectCityActivity.class));
2875
                startActivity(new Intent(getApplicationContext(), NewSelectCityActivity.class));
2883 2876
//                startActivityForResult(new Intent(getApplication(), SelectCityActivity.class), SEARCH_CODE);
2884 2877
                if (ll_tuijian.getVisibility() == View.VISIBLE) {
2885 2878
                    ll_tuijian.setVisibility(View.GONE);
@ -2898,15 +2891,15 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
2898 2891
                        e.printStackTrace();
2899 2892
                    }
2900 2893
                }
2901
                if (!MainApplication.isLogin()){
2894
                if (!MainApplication.isLogin()) {
2902 2895
                    startActivity(new Intent(getApplication(), LoginActivity.class));
2903
                }else if (!cameraTask()){
2896
                } else if (!cameraTask()) {
2904 2897
                    EasyPermissions.requestPermissions(
2905 2898
                            this,
2906 2899
                            "该功能需要开启摄像头权限,是否前往开启?",
2907 2900
                            RC_CAMERA_PERM,
2908 2901
                            Manifest.permission.CAMERA);
2909
                }else {
2902
                } else {
2910 2903
                    Intent iintent = new Intent(getApplicationContext(), com.google.zxing.client.android.CaptureActivity.class);
2911 2904
                    iintent.putExtra("url", MainApplication.url);
2912 2905
                    iintent.putExtra("user_id", MainApplication.userId);
@ -3349,7 +3342,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
3349 3342
3350 3343
    @Override
3351 3344
    public void onPermissionsDenied(int requestCode, List<String> perms) {
3352
        for (String s:perms){
3345
        for (String s : perms) {
3353 3346
            LogUtils.e(s);
3354 3347
        }
3355 3348
        if (EasyPermissions.somePermissionPermanentlyDenied(this, perms)) {
@ -3728,7 +3721,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
3728 3721
            }
3729 3722
        }
3730 3723
3731
            return true;
3724
        return true;
3732 3725
//        return super.onKeyDown(keyCode, event);
3733 3726
    }
3734 3727
@ -3816,7 +3809,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
3816 3809
        }
3817 3810
    }
3818 3811
3819
    private void showProgressWindow(){
3812
    private void showProgressWindow() {
3820 3813
        updateDialog = new UpdateDialog(MainMapActivity.this);
3821 3814
        updateDialog.builder().setMsg("").setCancelable(false).show();
3822 3815
    }
@ -3824,7 +3817,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
3824 3817
    private void dialogup_other() {
3825 3818
        int code = Integer.parseInt(now_versionCode);
3826 3819
        if (code - getVersionCode(getApplication()) > 0) {
3827
           alterDialog = new AlertDialogTwo(MainMapActivity.this);
3820
            alterDialog = new AlertDialogTwo(MainMapActivity.this);
3828 3821
3829 3822
            alterDialog.builder()
3830 3823
                    .setTitle("更新提示 V" + now_versionName)
@ -3833,9 +3826,9 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
3833 3826
                        @Override
3834 3827
                        public void onClick(View v) {
3835 3828
                            showProgressWindow();
3836
                            ToastUtil.showToast(getApplicationContext(),"正在下载中",Toast.LENGTH_SHORT);
3829
                            ToastUtil.showToast(getApplicationContext(), "正在下载中", Toast.LENGTH_SHORT);
3837 3830
                            OkHttpUtils.get().url("http://cdz.evcharge.cc/app/app.apk").build()
3838
                                    .execute(new FileCallBack(Environment.getExternalStorageDirectory().getAbsolutePath(),"cdz_install") {
3831
                                    .execute(new FileCallBack(Environment.getExternalStorageDirectory().getAbsolutePath(), "cdz_install") {
3839 3832
                                        @Override
3840 3833
                                        public void inProgress(final float progress, long total) {
3841 3834
@ -3844,27 +3837,25 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
3844 3837
                                            // 设置精确到小数点后2位
3845 3838
3846 3839
                                            numberFormat.setMaximumFractionDigits(2);
3847
                                            String format = numberFormat.format(progress*100);
3840
                                            String format = numberFormat.format(progress * 100);
3848 3841
3849 3842
                                            Message message = new Message();
3850 3843
                                            message.what = 0x01;
3851 3844
3852 3845
                                            Bundle bundle = new Bundle();
3853 3846
                                            bundle.putString("format", format + "%");
3854
                                            LogUtils.e("当前:"+format);
3847
                                            LogUtils.e("当前:" + format);
3855 3848
                                            if (!format.contains(".")) {
3856
                                                bundle.putString("progress", format+".");
3849
                                                bundle.putString("progress", format + ".");
3857 3850
                                            } else {
3858 3851
                                                bundle.putString("progress", format);
3859 3852
                                            }
3860 3853
3861 3854
3862
3863 3855
                                            message.setData(bundle);
3864 3856
                                            myHandler.sendMessage(message);
3865 3857
3866 3858
3867
3868 3859
                                        }
3869 3860
3870 3861
                                        @Override
@ -4285,10 +4276,10 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
4285 4276
        }
4286 4277
    }
4287 4278
4288
    private void userChargingCheck(){
4279
    private void userChargingCheck() {
4289 4280
        OkHttpUtils.get().url(UrlConstants.USER_CHARGING_CHECK_URL)
4290
                .addParams(ChargingConstants.USERID,MainApplication.userId)
4291
                .addParams(ChargingConstants.PWD,MainApplication.userPassword)
4281
                .addParams(ChargingConstants.USERID, MainApplication.userId)
4282
                .addParams(ChargingConstants.PWD, MainApplication.userPassword)
4292 4283
                .build().connTimeOut(10000).readTimeOut(10000).execute(new StringCallback() {
4293 4284
            @Override
4294 4285
            public void onError(Call call, Exception e) {
@ -4299,8 +4290,8 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
4299 4290
            public void onResponse(final String response) {
4300 4291
                LogUtils.e(response);
4301 4292
                if (EmptyUtils.isNotEmpty(response)) {
4302
                    String rtnCode = JsonUtils.getKeyResult(response,"rtnCode");
4303
                    if ("306".equals(rtnCode)){
4293
                    String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
4294
                    if ("306".equals(rtnCode)) {
4304 4295
                        LogUtils.e("有订单");
4305 4296
                        rl_charging_notice.setVisibility(View.VISIBLE);
4306 4297
                        if (firstCheck) {
@ -4324,11 +4315,11 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
4324 4315
                            }
4325 4316
                        });
4326 4317
4327
                    }else {
4318
                    } else {
4328 4319
                        LogUtils.e("没有订单");
4329 4320
                        rl_charging_notice.setVisibility(View.GONE);
4330 4321
                        MainApplication.isAppStart = false;
4331
                        ProfileManager.getInstance().setAppStart(getApplicationContext(),MainApplication.isAppStart);
4322
                        ProfileManager.getInstance().setAppStart(getApplicationContext(), MainApplication.isAppStart);
4332 4323
                    }
4333 4324
                }
4334 4325
            }
@ -4665,7 +4656,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
4665 4656
4666 4657
//        zhan_lists = zhan_listDao.loadAll();
4667 4658
        zhan_lists = zhan_listDao.queryRaw("where status = ? " + MainApplication.sql, new String[]{"4"});
4668
        LogUtils.e(zhan_lists.size()+"-----");
4659
        LogUtils.e(zhan_lists.size() + "-----");
4669 4660
//        Log.e(TAG, "getZhanData: "+"where status = ? "+MainApplication.sql);
4670 4661
        if (onResumeRefresh == true) {
4671 4662
//            Log.e(TAG, "getZhanData: "+"共" );
@ -4787,12 +4778,12 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
4787 4778
        fileOutputStream.close();
4788 4779
//        Log.d(TAG, "initDataBase: length=" + databasePath.length());
4789 4780
4790
                eteinit("{\"fun\":\"timer\"}");
4791
                try {
4792
                    getZhanData();
4793
                } catch (Exception e) {
4794
                    e.printStackTrace();
4795
                }
4781
        eteinit("{\"fun\":\"timer\"}");
4782
        try {
4783
            getZhanData();
4784
        } catch (Exception e) {
4785
            e.printStackTrace();
4786
        }
4796 4787
4797 4788
    }
4798 4789
@ -4957,7 +4948,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
4957 4948
                dialog.cancel();
4958 4949
                String info = JsonUtils.getKeyResult(response, "info");
4959 4950
//                String info = "JbCMZl5FRHmpKqIywO0ntFtBJfaZYHk7bQGy9WjREYixObR+49H+MAJTiHTKnvSQz73LDfLo4MQMAldzbOFyNkhapUrlWOF5Og7H8HmFX/0A1mLAIDGIXMepmpS45gYVdzn8xvGDh3JXdiNU1AAohz4R3WdpSIo5Pvt+RbsIqH+/Uuk3/mRrizGxZmWhQzzIpc9KMY/69vUAEaxTz8YQLgdbHWUE/wD1e79BiXKTRmrbqayVFd8tFDrM6pvovDE15wUomION2gKdHLCvA2Dg5loIiany/FVkB7tmQLu2SiiCgfHArwWqr/axUP9Vbu878PrJRxLYSW616iFSBFYJHVe1PIDTXA6g8mvxUnCCnfhUVoRJ5mn18hXo2EsTdqbLnp3UpOAXicoGWoP4ztXu/M2P0xA+MnPk7Wa4NunMhPVeKpmTsYXV2RzQaUQknwtEgSRvtTEX6HSUxPnrNESiQML5fLCNiWms2z5vp2GUSFYQTGKnCsqlw7HsAJCf0VBJAz6Ii46kr8NBtk3WwOfld5ZO/pIhTuS3Mg1HHlu9nR1Vqu6/UPJiu0zF1AfOUB1f1mSM3d1p2tsPSGKbugRIP7vWOQ57vgUYK3n3UUo51aCemgpy3eIxo9cCdtTEXU5O4A4FpyQEKP8uIiAp7dIUqvkCGfatTI/dJVJ70Sv5sCpXCfdYIRpiWVj63nt8p4KUnxF7x5KrMDiZY+ntQLXzufgIHa+pL6E/ToJ2lznXaMOaMSt0O2bWz++2qa2TvpOj7S9qsaJgtySs7Mwrk+Yg3UULyp8BkMK6lcRxBv4jz43pt84fPO4imm42SDr/H0X/88CmmyhzJtLExchpZQA1nqmTyWkfj9V0Z62s+9IAcw90bHm/J6x5vSY3K+N5chBR47VEt77tg6DKPTW2u9R+lDGEPluYvPjZ2i20qeDkUJ19U6vM+QnYF8Sa4AlzT3G9SJlqHGyXRyTn7WOLnvg6pSKSAsTp/lFAaeNHAvJtx1bSq+43vDlFbs6jXPQXcVvTZf6ALge/rLFItYA8muOwKj2DxFftshKFwkufxA/nTS19rJoDNvLtVbTfe6E3Za2ei7LCaWNV5UtrDJOSdEGzFKqroB59Ika0Ijdn1ZI2f54feYgnUYZHKDb8UUbGQlRWzwcYBv4PjDGVVKbSWUMkeDA0FB4t+X1Rfu28UnSJ2GShL8cotnm6vwD1Psy3NDAShfvCBVqSx6O6PqTic0KBQq2Ufjlx1OWKexE08qEWWUEyEvMOPkTx2t94zdxQZVCIfR1DIvHCklvBTh7zyfcLXQol/6AnoTBh6X+R8Hh1Ih8FLnlZfeB4bde8hHZbNS2GyQb8Hs4haZmeYyVdUYy3OuXIBFd1Ve5UzKv+AY1JipsKI/ha/h19Xozpvr86sQUYDhlpbKyYAVtrZhYvTFcKuj6Jl46KGkJMXv6GU1QpYvjxF8W156HfGv9uN35Q1bVVcHOXerM4e8DXqUvXTK6g5zMTPes0smYLlTn73CO1iuc4c2wDmEiTEk367qJf6VDefWPRZpkOsKZHxc06OTfw3tAuEK9X8mnVaVhb+6OHkPKtnD//5K/6VYYPcXaIoSAcFdkgcMkYe5vSKyw7TNfgSBSGNlxFrYPkhotshDoKt6FP/KTn9lFxQtl/BKG6if5wfp2hp7Ufn339wJh6SKd7ibtM38AS3HFHxvq7pC+wREAkhW4gyD8t7S3BZKsw+M50vhI3rmg9gebH4MJxC2iK5JDhPnHyw6fVz72pgluqD0cWpvy/3hFt+QxFfpbVnMhC6fvmspLpk/WZf3CKIb5T8TLoUOSMX7wBlTrl+oh6A0c/OdUpScoIv1dFGSN/7FXXnWLlMz4nkRcsN3ob6RT/QXqaE3cpo8HmR/6x9A+qNkMvVndDLBw3v/S4Fq6pr1DVsJpYAhwmgx461Z1pQTB+ORKDZOdiz+WAeHzNH5tD2Ers4VK8IWoK/FX1JABSC3Qxad3gUTAGc7Bpx4VZ8fdGzr6gfMeg8HT5WSeCkffepjLTQ0+Z4S+vjQ==";
4960
                Log.e(TAG, "onResponse: info="+info );
4951
                Log.e(TAG, "onResponse: info=" + info);
4961 4952
                String info_decode = "";
4962 4953
                try {
4963 4954
                    info_decode = DES3S.decode(info);
@ -4995,9 +4986,9 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
4995 4986
        if (remind.equals("0") && !"1".equals(own_pay)) {
4996 4987
            iv_guzhang.setVisibility(View.GONE);
4997 4988
        } else {
4998
            if (!remind.equals("0")){
4989
            if (!remind.equals("0")) {
4999 4990
                iv_guzhang.setImageResource(R.drawable.icon_guzhang_window);
5000
            }else {
4991
            } else {
5001 4992
                iv_guzhang.setImageResource(R.drawable.icon_is_cost);
5002 4993
            }
5003 4994
            iv_guzhang.setVisibility(View.VISIBLE);
@ -5290,9 +5281,9 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
5290 5281
                if (finalRemind.equals("0")) {
5291 5282
                    if (!isAvilible(getApplicationContext(), "com.baidu.BaiduMap") &&
5292 5283
                            !isAvilible(getApplicationContext(), "com.autonavi.minimap")) {
5293
                        if (null == center){
5294
                            ToastUtil.showToast(getApplicationContext(),"请检查您当前网络或定位权限是否开启",Toast.LENGTH_SHORT);
5295
                        }else {
5284
                        if (null == center) {
5285
                            ToastUtil.showToast(getApplicationContext(), "请检查您当前网络或定位权限是否开启", Toast.LENGTH_SHORT);
5286
                        } else {
5296 5287
                            Intent intent = new Intent(getApplication(), BasicNaviActivity.class);
5297 5288
                            intent.putExtra("start_jing", center.longitude + "");
5298 5289
                            intent.putExtra("start_wei", center.latitude + "");
@ -5426,7 +5417,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
5426 5417
                                    .show();
5427 5418
                        }
5428 5419
                    }
5429
                }else {
5420
                } else {
5430 5421
                    new com.electric.chargingpile.view.AlertDialog(MainMapActivity.this).builder()
5431 5422
                            .setMsg("站点充电桩均为离线或故障,可能无法正常充电,是否继续前往")
5432 5423
                            .setPositiveButton("继续", new View.OnClickListener() {
@ -5561,7 +5552,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
5561 5552
                                            popupWindow.showAtLocation(cancleButton, Gravity.CENTER, 0, 0);
5562 5553
//                                            startNavi(center, ll);
5563 5554
                                        } else {
5564
                                            ToastUtil.showToast(getApplicationContext(),"请检查您当前网络或定位权限是否开启",Toast.LENGTH_SHORT);
5555
                                            ToastUtil.showToast(getApplicationContext(), "请检查您当前网络或定位权限是否开启", Toast.LENGTH_SHORT);
5565 5556
                                        }
5566 5557
                                    }
5567 5558
                                }
@ -5723,7 +5714,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
5723 5714
    }
5724 5715
5725 5716
5726
    private void getMessageNum(){
5717
    private void getMessageNum() {
5727 5718
        long appTime1 = System.currentTimeMillis() / 1000;
5728 5719
        String token = String.valueOf(appTime1);
5729 5720
        if (MainApplication.msgTime.equals("0")) {
@ -5732,9 +5723,9 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
5732 5723
            MainApplication.msgTime = token;
5733 5724
            ProfileManager.getInstance().setSystemMsgTime(getApplicationContext(), token);
5734 5725
        }
5735
        String url = MainApplication.url+"/zhannew/basic/web/index.php/question/center?user_id="+
5736
                MainApplication.userId+"&timer="+MainApplication.msgTime+"&phone="+MainApplication.userPhone
5737
                +"&password="+MainApplication.userPassword;
5726
        String url = MainApplication.url + "/zhannew/basic/web/index.php/question/center?user_id=" +
5727
                MainApplication.userId + "&timer=" + MainApplication.msgTime + "&phone=" + MainApplication.userPhone
5728
                + "&password=" + MainApplication.userPassword;
5738 5729
//        Log.e(TAG, "getMessageNum: url="+url );
5739 5730
        OkHttpUtils.get().tag(MainMapActivity.this).url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
5740 5731
            @Override
@ -5745,17 +5736,17 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
5745 5736
            @Override
5746 5737
            public void onResponse(String response) {
5747 5738
//                Log.e(TAG, "onResponse: "+response );
5748
                String rtnCode = JsonUtils.getKeyResult(response,"rtnCode");
5749
                if ("01".equals(rtnCode)){
5750
                    String rtnMsg = JsonUtils.getKeyResult(response,"rtnMsg");
5751
                    question_unread = Integer.parseInt(JsonUtils.getKeyResult(rtnMsg,"question_unread"));
5752
                    comment_unread = Integer.parseInt(JsonUtils.getKeyResult(rtnMsg,"comment_unread"));
5753
                    system_unread = Integer.parseInt(JsonUtils.getKeyResult(rtnMsg,"system_unread"));
5754
                    total_unread = question_unread+comment_unread+system_unread;
5755
                    if (total_unread > 0){
5739
                String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
5740
                if ("01".equals(rtnCode)) {
5741
                    String rtnMsg = JsonUtils.getKeyResult(response, "rtnMsg");
5742
                    question_unread = Integer.parseInt(JsonUtils.getKeyResult(rtnMsg, "question_unread"));
5743
                    comment_unread = Integer.parseInt(JsonUtils.getKeyResult(rtnMsg, "comment_unread"));
5744
                    system_unread = Integer.parseInt(JsonUtils.getKeyResult(rtnMsg, "system_unread"));
5745
                    total_unread = question_unread + comment_unread + system_unread;
5746
                    if (total_unread > 0) {
5756 5747
                        tv_msg_num.setVisibility(View.VISIBLE);
5757
                        tv_msg_num.setText(total_unread+"");
5758
                    }else {
5748
                        tv_msg_num.setText(total_unread + "");
5749
                    } else {
5759 5750
                        tv_msg_num.setVisibility(View.GONE);
5760 5751
                    }
5761 5752
                }
@ -5766,20 +5757,20 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
5766 5757
    //Eventbus的方法
5767 5758
    @Subscribe(threadMode = ThreadMode.MAIN)
5768 5759
    public void handleEvent(BaseEvent event) {
5769
        if (event.getType().equals(BaseConstants.EVENT_SELECT_CITY)){
5760
        if (event.getType().equals(BaseConstants.EVENT_SELECT_CITY)) {
5770 5761
5771 5762
            String locationCity = MainApplication.getInstance().getmCurrentCity();
5772 5763
            tv_atCity.setText(locationCity);
5773 5764
            MainApplication.atCity = locationCity;
5774
            final LatLng cityLatLng = new LatLng(event.getPoi_lat(),event.getPoi_lon());
5765
            final LatLng cityLatLng = new LatLng(event.getPoi_lat(), event.getPoi_lon());
5775 5766
            new Handler().postDelayed(new Runnable() {
5776 5767
                @Override
5777 5768
                public void run() {
5778
                    aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(cityLatLng,14.0f));
5769
                    aMap.moveCamera(CameraUpdateFactory.newLatLngZoom(cityLatLng, 14.0f));
5779 5770
                }
5780
            },500);
5771
            }, 500);
5781 5772
5782
        }else {
5773
        } else {
5783 5774
            if (!isFirstLoc) {
5784 5775
                isFirstLoc = true;
5785 5776
                mLocationOption.setLocationMode(AMapLocationMode.Hight_Accuracy);
@ -5806,13 +5797,13 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
5806 5797
                        int tag = (int) itemView.getTag();
5807 5798
                        switch (tag) {
5808 5799
                            case TAG_SHARE_WECHAT_FRIEND:
5809
                                share(Wechat.NAME,chargingShareBean);
5800
                                share(Wechat.NAME, chargingShareBean);
5810 5801
                                break;
5811 5802
                            case TAG_SHARE_WECHAT_MOMENT:
5812
                                share(WechatMoments.NAME,chargingShareBean);
5803
                                share(WechatMoments.NAME, chargingShareBean);
5813 5804
                                break;
5814 5805
                            case TAG_SHARE_QQ:
5815
                                share(QQ.NAME,chargingShareBean);
5806
                                share(QQ.NAME, chargingShareBean);
5816 5807
                                break;
5817 5808
                        }
5818 5809
                    }
@ -5821,7 +5812,7 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
5821 5812
        build.show();
5822 5813
    }
5823 5814
5824
    private void share(final String name,ChargingShareBean chargingShareBean) {
5815
    private void share(final String name, ChargingShareBean chargingShareBean) {
5825 5816
        Platform.ShareParams paramsToShare = new Platform.ShareParams();
5826 5817
        paramsToShare.setText(chargingShareBean.getText());
5827 5818
        paramsToShare.setTitle(chargingShareBean.getTitle());
@ -5851,14 +5842,14 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
5851 5842
        platform.share(paramsToShare);
5852 5843
    }
5853 5844
5854
    private void getRecyclerViewData(){
5845
    private void getRecyclerViewData() {
5855 5846
        String findDate = ProfileManager.getInstance().getFindDate(MainMapActivity.this);
5856
        if (EmptyUtils.isEmpty(findDate)){
5847
        if (EmptyUtils.isEmpty(findDate)) {
5857 5848
            findDate = String.valueOf(System.currentTimeMillis() / 1000);
5858
            ProfileManager.getInstance().setFindDate(MainMapActivity.this,findDate);
5849
            ProfileManager.getInstance().setFindDate(MainMapActivity.this, findDate);
5859 5850
        }
5860
        String url = MainApplication.url+"/zhannew/basic/web/index.php/discovery/menu-list";
5861
        OkHttpUtils.get().url(url).addParams("timer",findDate).build().execute(new StringCallback() {
5851
        String url = MainApplication.url + "/zhannew/basic/web/index.php/discovery/menu-list";
5852
        OkHttpUtils.get().url(url).addParams("timer", findDate).build().execute(new StringCallback() {
5862 5853
            @Override
5863 5854
            public void onError(Call call, Exception e) {
5864 5855
@ -5870,12 +5861,12 @@ public class MainMapActivity extends Activity implements LocationSource, AMapLoc
5870 5861
                if (EmptyUtils.isNotEmpty(response)) {
5871 5862
                    String rtnCode = JsonUtils.getKeyResult(response, "rtnCode");
5872 5863
                    if ("01".equals(rtnCode)) {
5873
                        String data = JsonUtils.getKeyResult(response,"data");
5874
                        List<FindData> list= JsonUtils.parseToObjectList(data,FindData.class);
5864
                        String data = JsonUtils.getKeyResult(response, "data");
5865
                        List<FindData> list = JsonUtils.parseToObjectList(data, FindData.class);
5875 5866
                        LogUtils.e(list.size());
5876
                        if (list.size() >0) {
5877
                            for (FindData findData : list){
5878
                                if (findData.getUnread().equals("0")){
5867
                        if (list.size() > 0) {
5868
                            for (FindData findData : list) {
5869
                                if (findData.getUnread().equals("0")) {
5879 5870
                                    FindActivity.haveFindMessage = true;
5880 5871
                                    iVpoint.setVisibility(View.VISIBLE);
5881 5872
                                    return;

+ 1 - 1
app/src/main/java/com/electric/chargingpile/activity/QaActivity.java

@ -94,7 +94,7 @@ public class QaActivity extends AppCompatActivity implements View.OnClickListene
94 94
        lv_info = (PullToRefreshListView) findViewById(R.id.lv_info);
95 95
        tv_help = (TextView) findViewById(R.id.tv_help);
96 96
        tv_msg_num = (TextView) findViewById(R.id.tv_msg_num);
97
        iVPoint = findViewById(R.id.iv_point);
97
        iVPoint = (ImageView)findViewById(R.id.iv_point);
98 98
    }
99 99
100 100
    private void initListener(){

+ 7 - 4
app/src/main/java/com/electric/chargingpile/activity/TalkActivity.java

@ -32,6 +32,8 @@ import com.electric.chargingpile.manager.ProfileManager;
32 32
import com.electric.chargingpile.util.BarColorUtil;
33 33
import com.electric.chargingpile.util.JsonUtils;
34 34
import com.electric.chargingpile.util.ToastUtil;
35
import com.electric.chargingpile.view.VideoCommentDialog;
36
import com.electric.chargingpile.view.VideoPubilshDialog;
35 37
import com.handmark.pulltorefresh.library.PullToRefreshBase;
36 38
import com.handmark.pulltorefresh.library.PullToRefreshListView;
37 39
import com.umeng.analytics.MobclickAgent;
@ -86,6 +88,10 @@ public class TalkActivity extends AppCompatActivity implements View.OnClickListe
86 88
        isRefresh = true;
87 89
        MobclickAgent.onEvent(getApplicationContext(),"0071");
88 90
        setBackground(0);
91
92
93
        VideoCommentDialog videoPubilshDialog = new VideoCommentDialog(this);
94
        videoPubilshDialog.show();
89 95
    }
90 96
91 97
    private void initViews(){
@ -96,7 +102,7 @@ public class TalkActivity extends AppCompatActivity implements View.OnClickListe
96 102
        tab_find = (RelativeLayout) findViewById(R.id.ll_tab_find);
97 103
        tab_me = (LinearLayout) findViewById(R.id.tab_me);
98 104
        tv_msg_num = (TextView) findViewById(R.id.tv_msg_num);
99
        iVPoint = findViewById(R.id.iv_point);
105
        iVPoint = (ImageView) findViewById(R.id.iv_point);
100 106
        viewPager = (ViewPager) findViewById(R.id.viewPager);
101 107
        textview_tj = (TextView) findViewById(R.id.textview_tj);
102 108
        textview_hd = (TextView) findViewById(R.id.textview_hd);
@ -133,13 +139,10 @@ public class TalkActivity extends AppCompatActivity implements View.OnClickListe
133 139
        @Override
134 140
        public void onPageScrolled(int position, float positionOffset,
135 141
                                   int positionOffsetPixels) {
136
//            resetViewPagerHeight(position);
137 142
        }
138 143
139 144
        @Override
140 145
        public void onPageSelected(int position) {
141
            // 页面切换后重置ViewPager高度
142
//            resetViewPagerHeight(position);
143 146
            setBackground(position);
144 147
        }
145 148
    }

+ 1 - 3
app/src/main/java/com/electric/chargingpile/activity/UnansweredActivity.java

@ -1,15 +1,13 @@
1 1
package com.electric.chargingpile.activity;
2 2
3
import android.support.v7.app.AppCompatActivity;
4 3
import android.os.Bundle;
5
import android.util.Log;
4
import android.support.v7.app.AppCompatActivity;
6 5
import android.view.View;
7 6
import android.widget.ImageView;
8 7
import android.widget.ListView;
9 8
import android.widget.Toast;
10 9
11 10
import com.electric.chargingpile.R;
12
import com.electric.chargingpile.adapter.QADataAdapter;
13 11
import com.electric.chargingpile.adapter.UnansweredAdapter;
14 12
import com.electric.chargingpile.application.MainApplication;
15 13
import com.electric.chargingpile.data.UnansweredBean;

+ 123 - 0
app/src/main/java/com/electric/chargingpile/activity/VideoDetaislActivity.java

@ -0,0 +1,123 @@
1
package com.electric.chargingpile.activity;
2
3
import android.app.Activity;
4
import android.os.Bundle;
5
import android.os.Handler;
6
import android.support.annotation.Nullable;
7
import android.support.v4.view.ViewPager;
8
import android.view.View;
9
10
import com.electric.chargingpile.R;
11
import com.electric.chargingpile.adapter.SvVideoPagerAdapter;
12
import com.electric.chargingpile.data.TalkRecommendBean;
13
import com.electric.chargingpile.fragment.SvVideoShowView;
14
import com.electric.chargingpile.view.VideoPubilshDialog;
15
import com.electric.chargingpile.view.sview.VerticalViewPager;
16
17
import java.lang.ref.WeakReference;
18
import java.util.List;
19
20
public class VideoDetaislActivity extends Activity implements View.OnClickListener {
21
22
    private VerticalViewPager pager_video;
23
24
    private SvVideoPagerAdapter viewPagerAdapter;
25
    private SvVideoShowView videoShowView;
26
27
    private MyHandler mHandler = new MyHandler(this);
28
29
30
    static class MyHandler extends Handler {
31
        private WeakReference<VideoDetaislActivity> mWeakReference;
32
33
        public MyHandler(VideoDetaislActivity activity) {
34
            mWeakReference = new WeakReference<VideoDetaislActivity>(activity);
35
        }
36
37
    }
38
39
    @Override
40
    protected void onCreate(@Nullable Bundle savedInstanceState) {
41
        super.onCreate(savedInstanceState);
42
        setContentView(R.layout.activity_videodetails);
43
44
        pager_video = findViewById(R.id.pager_video);
45
46
        viewPagerAdapter = new SvVideoPagerAdapter(this, new SvVideoShowView.OnDeleteVideoListener() {
47
            @Override
48
            public void onDelete() {
49
50
            }
51
        });
52
        pager_video.setAdapter(viewPagerAdapter);
53
        pager_video.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
54
            @Override
55
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
56
57
            }
58
59
            @Override
60
            public void onPageSelected(int position) {
61
62
            }
63
64
            @Override
65
            public void onPageScrollStateChanged(int state) {
66
67
            }
68
        });
69
        findViewById(R.id.vd_title_back).setOnClickListener(this);
70
        findViewById(R.id.vd_title_dot).setOnClickListener(this);
71
        addIntentInfo();
72
    }
73
74
75
    @Override
76
    public void onClick(View view) {
77
        switch (view.getId()) {
78
            case R.id.vd_title_dot:
79
                break;
80
            case R.id.vd_title_back:
81
                VideoPubilshDialog videoPubilshDialog = new VideoPubilshDialog(this);
82
                videoPubilshDialog.show();
83
                break;
84
        }
85
    }
86
87
88
    int position = 0;
89
    List<TalkRecommendBean> talkRecommendBeans;
90
91
    private void addIntentInfo() {
92
        position = getIntent().getIntExtra("pos", 0);
93
        talkRecommendBeans = (List<TalkRecommendBean>) getIntent().getSerializableExtra("list");
94
        viewPagerAdapter.notifyChanged(talkRecommendBeans);
95
        pager_video.setCurrentItem(position);
96
        viewPagerAdapter.setInitViewListener(new SvVideoPagerAdapter.InitViewListener() {
97
            @Override
98
            public void initFirstViewAfter() {
99
                initPlayByPostion(talkRecommendBeans, position, true);
100
            }
101
        });
102
    }
103
104
    private void initPlayByPostion(final List<TalkRecommendBean> videoInfos, final int position, final boolean isNeedSer) {
105
        videoShowView = viewPagerAdapter.getViewList(position % viewPagerAdapter.getList());
106
        if (videoShowView.getRootView() != null) {
107
108
            mHandler.postDelayed(new Runnable() {
109
                @Override
110
                public void run() {
111
                    if (isNeedSer) {
112
                        if (videoInfos.size() > 0 && position < videoInfos.size()) {
113
                            videoShowView.setInfo(videoInfos.get(position));
114
                        }
115
                    }
116
                    videoShowView.updateView();
117
                    videoShowView.initAndPlay();
118
                }
119
            }, 100);
120
121
        }
122
    }
123
}

+ 0 - 11
app/src/main/java/com/electric/chargingpile/activity/WelcomeActivity.java

@ -5,12 +5,10 @@ import android.annotation.TargetApi;
5 5
import android.app.Activity;
6 6
import android.content.DialogInterface;
7 7
import android.content.Intent;
8
import android.content.SharedPreferences;
9 8
import android.content.pm.PackageInfo;
10 9
import android.content.pm.PackageManager;
11 10
import android.graphics.Bitmap;
12 11
import android.graphics.drawable.Drawable;
13
import android.net.Uri;
14 12
import android.os.Build;
15 13
import android.os.Bundle;
16 14
import android.os.Environment;
@ -31,13 +29,9 @@ import android.widget.Toast;
31 29

32 30
import com.alibaba.fastjson.JSON;
33 31
import com.amap.api.maps.MapsInitializer;
34
import com.blankj.utilcode.util.BarUtils;
35 32
import com.blankj.utilcode.util.CacheUtils;
36
import com.blankj.utilcode.util.CleanUtils;
37 33
import com.blankj.utilcode.util.EmptyUtils;
38
import com.blankj.utilcode.util.FileUtils;
39 34
import com.blankj.utilcode.util.LogUtils;
40
import com.blankj.utilcode.util.SPUtils;
41 35
import com.blankj.utilcode.util.StringUtils;
42 36
import com.electric.chargingpile.R;
43 37
import com.electric.chargingpile.application.MainApplication;
@ -48,9 +42,6 @@ import com.electric.chargingpile.util.BarColorUtil;
48 42
import com.electric.chargingpile.util.DES3;
49 43
import com.electric.chargingpile.util.JsonUtils;
50 44
import com.electric.chargingpile.util.OkHttpUtil;
51

52
import com.electric.chargingpile.util.SpUtils;
53
import com.electric.chargingpile.util.ToastUtil;
54 45
import com.electric.chargingpile.view.ViewPagerAdapter;
55 46
import com.google.gson.Gson;
56 47
import com.google.gson.reflect.TypeToken;
@ -77,7 +68,6 @@ import java.net.URL;
77 68
import java.net.URLEncoder;
78 69
import java.security.MessageDigest;
79 70
import java.util.ArrayList;
80
import java.util.Arrays;
81 71
import java.util.List;
82 72
import java.util.Timer;
83 73
import java.util.TimerTask;
@ -85,7 +75,6 @@ import java.util.TimerTask;
85 75
import cn.jpush.android.api.JPushInterface;
86 76
import okhttp3.Call;
87 77
import pub.devrel.easypermissions.AfterPermissionGranted;
88
import pub.devrel.easypermissions.AppSettingsDialog;
89 78
import pub.devrel.easypermissions.EasyPermissions;
90 79

91 80
public class WelcomeActivity extends Activity implements OnClickListener ,EasyPermissions.PermissionCallbacks{

+ 12 - 12
app/src/main/java/com/electric/chargingpile/activity/ZoomingPhotoTextActivity.java

@ -91,32 +91,32 @@ public class ZoomingPhotoTextActivity extends FragmentActivity implements PhotoV
91 91
    }
92 92
93 93
    private void requestServer() {
94
        String url = MainApplication.urlNew+"/topic/detail.do";
95
        Map<String,String> map = new HashMap<>();
96
        map.put("targetId",targetId);
97
        map.put("targetType",targetType);
98
        map.put("limit","3");
94
        String url = MainApplication.urlNew + "/topic/detail.do";
95
        Map<String, String> map = new HashMap<>();
96
        map.put("targetId", targetId);
97
        map.put("targetType", targetType);
98
        map.put("limit", "3");
99 99
        OkHttpUtils.get().params(map).url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
100 100
            @Override
101 101
            public void onError(Call call, Exception e) {
102
                ToastUtil.showToast(ZoomingPhotoTextActivity.this,"加载失败,请重试",Toast.LENGTH_SHORT);
102
                ToastUtil.showToast(ZoomingPhotoTextActivity.this, "加载失败,请重试", Toast.LENGTH_SHORT);
103 103
            }
104 104
105 105
            @Override
106 106
            public void onResponse(String response) {
107
                String rtnCode = JsonUtils.getKeyResult(response,"code");
108
                if ("1000".equals(rtnCode)){
109
                    String rtnMsg = JsonUtils.getKeyResult(response,"data");
110
                    ArrayList <TopicDetailBean> topicDetailBeans = (ArrayList<TopicDetailBean>) JsonUtils.parseToObjectList(rtnMsg,TopicDetailBean.class);
107
                String rtnCode = JsonUtils.getKeyResult(response, "code");
108
                if ("1000".equals(rtnCode)) {
109
                    String rtnMsg = JsonUtils.getKeyResult(response, "data");
110
                    ArrayList<TopicDetailBean> topicDetailBeans = (ArrayList<TopicDetailBean>) JsonUtils.parseToObjectList(rtnMsg, TopicDetailBean.class);
111 111
                    setData(topicDetailBeans);
112 112
                }
113 113
            }
114 114
        });
115 115
    }
116 116
117
    private void setData(ArrayList <TopicDetailBean> topicDetailBeans){
117
    private void setData(ArrayList<TopicDetailBean> topicDetailBeans) {
118 118
        position = getIntent().getIntExtra("position", 0);
119
        for(int i=0;i<topicDetailBeans.size();i++){
119
        for (int i = 0; i < topicDetailBeans.size(); i++) {
120 120
            photoArrayList.add(topicDetailBeans.get(i).coverImgUrl);
121 121
        }
122 122
        act_zomming_current_pic_all.setText("/" + photoArrayList.size());

+ 37 - 18
app/src/main/java/com/electric/chargingpile/adapter/LayoutAdapter.java

@ -38,8 +38,10 @@ public class LayoutAdapter extends RecyclerView.Adapter<IViewHolder> {
38 38
    private ArrayList<TalkRecommendBean> talkRecommendBeans;
39 39
    private ArrayList<TalkRecommendBean> talkHeaderRecommendBeans;
40 40
    private RecyclerItemTypeClickListener onRecyclerItemClickListener;
41
    private OnItemClickListener onItemClickListener;
41 42
    private int screenWidth;
42
    public LayoutAdapter(Context context){
43
44
    public LayoutAdapter(Context context) {
43 45
        this.context = context;
44 46
        LayoutInflater = LayoutInflater.from(context);
45 47
        talkRecommendBeans = new ArrayList<>();
@ -47,21 +49,25 @@ public class LayoutAdapter extends RecyclerView.Adapter<IViewHolder> {
47 49
        screenWidth = ScreenUtils.getScreenWidth(context);
48 50
    }
49 51
50
    public void setData(ArrayList<TalkRecommendBean> datas){
52
    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
53
        this.onItemClickListener = onItemClickListener;
54
    }
55
56
    public void setData(ArrayList<TalkRecommendBean> datas) {
51 57
        talkRecommendBeans = datas;
52 58
        notifyDataSetChanged();
53 59
    }
54 60
55
    public void addData(ArrayList<TalkRecommendBean> datas){
61
    public void addData(ArrayList<TalkRecommendBean> datas) {
56 62
        talkRecommendBeans.addAll(datas);
57 63
        notifyDataSetChanged();
58 64
    }
59 65
60
    public ArrayList<TalkRecommendBean> getCurrentData(){
66
    public ArrayList<TalkRecommendBean> getCurrentData() {
61 67
        return talkRecommendBeans;
62 68
    }
63 69
64
    public void setHeaderData(ArrayList<TalkRecommendBean> datas){
70
    public void setHeaderData(ArrayList<TalkRecommendBean> datas) {
65 71
        talkHeaderRecommendBeans = datas;
66 72
    }
67 73
@ -94,6 +100,14 @@ public class LayoutAdapter extends RecyclerView.Adapter<IViewHolder> {
94 100
            case TYPE_ITEM:
95 101
                view = LayoutInflater.inflate(R.layout.app_talk_item_recylerview, parent, false);
96 102
                holder = new SimpleViewHolder(view);
103
//                holder.itemView.setOnClickListener(new View.OnClickListener() {
104
//                    @Override
105
//                    public void onClick(View view) {
106
//                        if (onItemClickListener != null) {
107
//                            onItemClickListener.onItemClick(view);
108
//                        }
109
//                    }
110
//                });
97 111
                break;
98 112
        }
99 113
        return holder;
@ -113,26 +127,26 @@ public class LayoutAdapter extends RecyclerView.Adapter<IViewHolder> {
113 127
    }
114 128
115 129
    private void setListHolder(IViewHolder holder, int position) {
116
        SimpleViewHolder simpleViewHolder = (SimpleViewHolder)holder;
130
        SimpleViewHolder simpleViewHolder = (SimpleViewHolder) holder;
117 131
118 132
        RelativeLayout.LayoutParams lpImg = (RelativeLayout.LayoutParams) simpleViewHolder.info_bg_icon.getLayoutParams();
119 133
120 134
//        LinearLayout.LayoutParams linearParams =(LinearLayout.LayoutParams) simpleViewHolder.user_avater.getLayoutParams(); //取控件textView当前的布局参数 linearParams.height = 20;// 控件的高强制设成20
121
        if(position%2 == 0){
122
            lpImg.width = screenWidth/2;
123
            lpImg.height = screenWidth * 2 / 3-100;
135
        if (position % 2 == 0) {
136
            lpImg.width = screenWidth / 2;
137
            lpImg.height = screenWidth * 2 / 3 - 100;
124 138
            simpleViewHolder.info_bg_icon.setLayoutParams(lpImg);
125
        }else {
126
            lpImg.width = screenWidth/2;
139
        } else {
140
            lpImg.width = screenWidth / 2;
127 141
            lpImg.height = screenWidth * 2 / 3;
128 142
            simpleViewHolder.info_bg_icon.setLayoutParams(lpImg);
129 143
        }
130 144
131
        TalkRecommendBean talkRecommendBean = talkRecommendBeans.get(position-1);
145
        TalkRecommendBean talkRecommendBean = talkRecommendBeans.get(position - 1);
132 146
        simpleViewHolder.recycler_view_title.setText(talkRecommendBean.title);
133
        simpleViewHolder.recycler_view_zan.setText(talkRecommendBean.likeNums+"");
147
        simpleViewHolder.recycler_view_zan.setText(talkRecommendBean.likeNums + "");
134 148
        simpleViewHolder.user_avater_name.setText(talkRecommendBean.nickName);
135
        if(talkRecommendBean.isTop == 0)
149
        if (talkRecommendBean.isTop == 0)
136 150
            simpleViewHolder.is_top_view.setVisibility(View.GONE);
137 151
        else
138 152
            simpleViewHolder.is_top_view.setVisibility(View.VISIBLE);
@ -148,14 +162,14 @@ public class LayoutAdapter extends RecyclerView.Adapter<IViewHolder> {
148 162
//            Picasso.with(context).load(talkRecommendBean.coverImgUrl).into(simpleViewHolder.info_bg_icon);
149 163
//        }
150 164
151
        if (TextUtils.isEmpty(talkRecommendBean.headImgUrl)){
165
        if (TextUtils.isEmpty(talkRecommendBean.headImgUrl)) {
152 166
            Picasso.with(context)
153 167
                    .load(R.drawable.icon_face2_0)
154 168
                    .placeholder(R.drawable.icon_face2_0)
155 169
                    .error(R.drawable.icon_face2_0)
156 170
                    .transform(new CircleTransform())
157 171
                    .into(simpleViewHolder.user_avater);
158
        }else {
172
        } else {
159 173
            Picasso.with(context)
160 174
                    .load(talkRecommendBean.headImgUrl)
161 175
                    .placeholder(R.drawable.icon_face2_0)
@ -168,7 +182,7 @@ public class LayoutAdapter extends RecyclerView.Adapter<IViewHolder> {
168 182
    private void setHeaderHolder(IViewHolder holder, int position) {
169 183
        // 根据view类型处理不同的操作
170 184
        // 获取cardview的布局属性,记住这里要是布局的最外层的控件的布局属性,如果是里层的会报cast错误
171
        SimpleHeaderViewHolder simpleHeaderViewHolder = (SimpleHeaderViewHolder)holder;
185
        SimpleHeaderViewHolder simpleHeaderViewHolder = (SimpleHeaderViewHolder) holder;
172 186
        StaggeredGridLayoutManager.LayoutParams clp = (StaggeredGridLayoutManager.LayoutParams) simpleHeaderViewHolder.cardview.getLayoutParams();
173 187
        // 最最关键一步,设置当前view占满列数,这样就可以占据两列实现头部了
174 188
        clp.setFullSpan(true);
@ -189,6 +203,7 @@ public class LayoutAdapter extends RecyclerView.Adapter<IViewHolder> {
189 203
        ImageView user_avater;
190 204
        ImageView info_bg_icon;
191 205
        LinearLayout cardview;
206
192 207
        public SimpleViewHolder(View view) {
193 208
            super(view);
194 209
            recycler_view_title = (TextView) view.findViewById(R.id.recycler_view_title);
@ -200,7 +215,7 @@ public class LayoutAdapter extends RecyclerView.Adapter<IViewHolder> {
200 215
            cardview = (LinearLayout) view.findViewById(R.id.cardview);
201 216
202 217
            RelativeLayout.LayoutParams lpImg = (RelativeLayout.LayoutParams) info_bg_icon.getLayoutParams();
203
            lpImg.width = screenWidth/2;
218
            lpImg.width = screenWidth / 2;
204 219
            lpImg.height = screenWidth * 2 / 3;
205 220
            info_bg_icon.setLayoutParams(lpImg);
206 221
@ -215,6 +230,10 @@ public class LayoutAdapter extends RecyclerView.Adapter<IViewHolder> {
215 230
        }
216 231
    }
217 232
233
    public static interface OnItemClickListener {
234
        void onItemClick(View view);
235
    }
236
218 237
    class SimpleHeaderViewHolder extends IViewHolder {
219 238
        // 头部的控件
220 239
        RecyclerView header_recy;

+ 100 - 0
app/src/main/java/com/electric/chargingpile/adapter/SvVideoPagerAdapter.java

@ -0,0 +1,100 @@
1
package com.electric.chargingpile.adapter;
2
3
import android.app.Activity;
4
import android.support.v4.view.PagerAdapter;
5
import android.view.View;
6
import android.view.ViewGroup;
7
8
import com.electric.chargingpile.data.TalkRecommendBean;
9
import com.electric.chargingpile.fragment.SvVideoShowView;
10
11
import java.util.ArrayList;
12
import java.util.HashMap;
13
import java.util.List;
14
import java.util.Map;
15
16
public class SvVideoPagerAdapter extends PagerAdapter {
17
    InitViewListener initViewListener;
18
    private Activity activity;
19
    private boolean isPlay;
20
21
    private List<TalkRecommendBean> videoInfoList = new ArrayList();
22
    private List<SvVideoShowView> list = new ArrayList();
23
    private Map<Integer, SvVideoShowView> vRoot = new HashMap<>(3);
24
25
    SvVideoShowView v1, v2, v3;
26
27
    public SvVideoPagerAdapter(Activity activity,
28
                               SvVideoShowView.OnDeleteVideoListener deleteVideoListener) {
29
        this.activity = activity;
30
        v1 = new SvVideoShowView(activity, deleteVideoListener);
31
        v2 = new SvVideoShowView(activity, deleteVideoListener);
32
        v3 = new SvVideoShowView(activity, deleteVideoListener);
33
        list.add(v1);
34
        list.add(v2);
35
        list.add(v3);
36
    }
37
38
    public void setIsPlay(boolean play) {
39
        isPlay = play;
40
    }
41
42
    @Override
43
    public int getCount() {
44
        return videoInfoList.size();
45
    }
46
47
    public void notifyChanged(List<TalkRecommendBean> videoInfos) {
48
        if (videoInfos != null) {
49
            videoInfoList.clear();
50
            videoInfoList.addAll(videoInfos);
51
            notifyDataSetChanged();
52
        }
53
    }
54
55
    @Override
56
    public Object instantiateItem(ViewGroup container, int position) {
57
        int temp = position % list.size();
58
        SvVideoShowView videoShowView;
59
        if (vRoot.get(temp) == null) {
60
            videoShowView = list.get(temp);
61
            videoShowView.addView(container);
62
            vRoot.put(temp, videoShowView);
63
        } else {
64
            videoShowView = vRoot.get(temp);
65
        }
66
        videoShowView.setInfo(videoInfoList.get(position));
67
        if (initViewListener != null) {
68
            initViewListener.initFirstViewAfter();
69
        }
70
        return videoShowView.getRootView();
71
    }
72
73
74
    public void setInitViewListener(InitViewListener initViewListener) {
75
        this.initViewListener = initViewListener;
76
    }
77
78
    @Override
79
    public boolean isViewFromObject(View view, Object object) {
80
        return view == object;
81
    }
82
83
    public int getList() {
84
        return list.size();
85
    }
86
87
    public SvVideoShowView getViewList(int i) {
88
        return list.get(i);
89
    }
90
91
92
    @Override
93
    public void destroyItem(ViewGroup container, int position, Object object) {
94
//        super.destroyItem(container, position, object);
95
    }
96
97
    public interface InitViewListener {
98
        void initFirstViewAfter();
99
    }
100
}

+ 119 - 0
app/src/main/java/com/electric/chargingpile/adapter/VideoCommentAdapter.java

@ -0,0 +1,119 @@
1
package com.electric.chargingpile.adapter;
2
3
import android.content.Context;
4
import android.support.annotation.NonNull;
5
import android.support.v7.widget.RecyclerView;
6
import android.view.View;
7
import android.view.ViewGroup;
8
import android.widget.ImageView;
9
import android.widget.LinearLayout;
10
import android.widget.TextView;
11
12
import com.bumptech.glide.Glide;
13
import com.bumptech.glide.request.RequestOptions;
14
import com.electric.chargingpile.R;
15
import com.electric.chargingpile.base.RecyclerViewHolder;
16
import com.electric.chargingpile.data.FindData;
17
import com.electric.chargingpile.data.VideoCommentBean;
18
19
import java.util.ArrayList;
20
import java.util.List;
21
22
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
23
24
public class VideoCommentAdapter extends RecyclerView.Adapter<VideoCommentAdapter.VideoCommentViewHolder> {
25
    private Context context;
26
    //    private OnItemClickListener mClickListener;
27
    private List<VideoCommentBean> dataList = new ArrayList<>();
28
29
    public VideoCommentAdapter(Context ctx) {
30
        this.context = ctx;
31
    }
32
33
34
    @NonNull
35
    @Override
36
    public VideoCommentViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
37
        return null;
38
    }
39
40
    @Override
41
    public void onBindViewHolder(@NonNull VideoCommentViewHolder viewHolder, int position) {
42
        VideoCommentBean videoCommentBean = dataList.get(position);
43
        int likeFlg = videoCommentBean.getLikeFlg();
44
        if (likeFlg == 0) {
45
            //not zan
46
//            viewHolder.mItemUserLikeImg = (ImageView) itemView.findViewById(R.id.item_user_like_img);
47
        } else {
48
            // zan
49
        }
50
51
        viewHolder.mItemUserLikeCount.setText(videoCommentBean.getLikeNums() + "");
52
53
54
        Glide.with(context).load(videoCommentBean.getHeadImgFromUser())
55
                .transition(withCrossFade()).into(viewHolder.mItemUserAvatar);
56
57
        viewHolder.mItemUserName.setText(videoCommentBean.getNickNameFromUser());
58
59
        viewHolder.mItemUserTime.setText(videoCommentBean.getAddDate());
60
        viewHolder.mItemUserCon.setText(videoCommentBean.getContent());
61
62
//        viewHolder.mItemUserOperation = (LinearLayout) itemView.findViewById(R.id.item_user_operation);
63
//        viewHolder.mItemUserReportLl = (LinearLayout) itemView.findViewById(R.id.item_user_report_ll);
64
        viewHolder.mItemUserReportCount.setText(videoCommentBean.getReplyNums() + "");
65
//        viewHolder.mItemUserDelete = (TextView) itemView.findViewById(R.id.item_user_delete);
66
67
68
    }
69
70
    @Override
71
    public int getItemCount() {
72
        return 0;
73
    }
74
75
    public void cleanData() {
76
77
    }
78
79
    public void addData(ArrayList<VideoCommentBean> qadata) {
80
        if (qadata != null) {
81
            dataList.addAll(qadata);
82
        }
83
        notifyDataSetChanged();
84
    }
85
86
    class VideoCommentViewHolder extends RecyclerView.ViewHolder {
87
88
        LinearLayout mItemUserCommentLike;
89
        ImageView mItemUserLikeImg;
90
        TextView mItemUserLikeCount;
91
        ImageView mItemUserAvatar;
92
        TextView mItemUserName;
93
        TextView mItemUserTime;
94
        TextView mItemUserCon;
95
        LinearLayout mItemUserOperation;
96
        LinearLayout mItemUserReportLl;
97
        TextView mItemUserReportCount;
98
        TextView mItemUserDelete;
99
100
        public VideoCommentViewHolder(View itemView) {
101
            super(itemView);
102
103
            mItemUserCommentLike = (LinearLayout) itemView.findViewById(R.id.item_user_comment_like);
104
            mItemUserLikeImg = (ImageView) itemView.findViewById(R.id.item_user_like_img);
105
            mItemUserLikeCount = (TextView) itemView.findViewById(R.id.item_user_like_count);
106
            mItemUserAvatar = (ImageView) itemView.findViewById(R.id.item_user_avatar);
107
            mItemUserName = (TextView) itemView.findViewById(R.id.item_user_name);
108
            mItemUserTime = (TextView) itemView.findViewById(R.id.item_user_time);
109
            mItemUserCon = (TextView) itemView.findViewById(R.id.item_user_con);
110
            mItemUserOperation = (LinearLayout) itemView.findViewById(R.id.item_user_operation);
111
            mItemUserReportLl = (LinearLayout) itemView.findViewById(R.id.item_user_report_ll);
112
            mItemUserReportCount = (TextView) itemView.findViewById(R.id.item_user_report_count);
113
            mItemUserDelete = (TextView) itemView.findViewById(R.id.item_user_delete);
114
115
116
        }
117
    }
118
}
119

+ 3 - 7
app/src/main/java/com/electric/chargingpile/data/CommentsBean.java

@ -1,13 +1,12 @@
1 1
package com.electric.chargingpile.data;
2 2
3 3
import java.io.Serializable;
4
import java.util.ArrayList;
5 4
import java.util.List;
6 5
7 6
/**
8 7
 * Created by Demon on 16/2/20.
9 8
 */
10
public class CommentsBean implements Serializable{
9
public class CommentsBean implements Serializable {
11 10
    private static final long serialVersionUID = 1L;
12 11
    public static final int MASTER_MOMMENT = 0;
13 12
    public static final int CHILD_MOMMENT = 1;
@ -17,10 +16,7 @@ public class CommentsBean implements Serializable{
17 16
    String id = "";
18 17
19 18
20
21
    int childCount ;
22
23
19
    int childCount;
24 20
25 21
26 22
    String parentid = "";
@ -47,7 +43,7 @@ public class CommentsBean implements Serializable{
47 43
    String star_level = "";
48 44
    String tag = "";
49 45
    int type;
50
    List<CommentsBean> childs ;
46
    List<CommentsBean> childs;
51 47
52 48
    public List<CommentsBean> getChilds() {
53 49
        return childs;

+ 24 - 1
app/src/main/java/com/electric/chargingpile/data/TalkRecommendBean.java

@ -1,6 +1,8 @@
1 1
package com.electric.chargingpile.data;
2 2
3
public class TalkRecommendBean {
3
import java.io.Serializable;
4
5
public class TalkRecommendBean implements Serializable {
4 6
//     "targetId": 4,
5 7
//             "targetType": 23,
6 8
//             "title": "这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件这是一个视频文件",
@ -30,4 +32,25 @@ public class TalkRecommendBean {
30 32
    public int isTop;
31 33
    public int likeFlg;
32 34
    public int source;
35
36
    @Override
37
    public String toString() {
38
        return "TalkRecommendBean{" +
39
                "targetId=" + targetId +
40
                ", addUserId=" + addUserId +
41
                ", targetType=" + targetType +
42
                ", title='" + title + '\'' +
43
                ", name='" + name + '\'' +
44
                ", topicId=" + topicId +
45
                ", joinNums=" + joinNums +
46
                ", coverImgUrl='" + coverImgUrl + '\'' +
47
                ", headImgUrl='" + headImgUrl + '\'' +
48
                ", nickName='" + nickName + '\'' +
49
                ", likeNums=" + likeNums +
50
                ", commentNums=" + commentNums +
51
                ", isTop=" + isTop +
52
                ", likeFlg=" + likeFlg +
53
                ", source=" + source +
54
                '}';
55
    }
33 56
}

+ 180 - 0
app/src/main/java/com/electric/chargingpile/data/VideoCommentBean.java

@ -0,0 +1,180 @@
1
package com.electric.chargingpile.data;
2
3
/**
4
 * Created by Demon on 16/11/22.
5
 */
6
7
public class VideoCommentBean {
8
    private String targetId = "";
9
    private int targetType;
10
    private int level;
11
    private String userId = "";
12
    private String nickNameFromUser = "";
13
    private String headImgFromUser = "";
14
    private String toUserId = "";
15
    private String nickNameToUser = "";
16
    private String headImgToUser = "";
17
    private String content = "";
18
    private int likeNums;
19
    private int likeFlg;
20
    private String addDate;
21
    private String commentsId;
22
    private String commentsId2;
23
24
    private String userId2;
25
    private String nickName2;
26
    private String content2;
27
    private String replyNums;
28
29
    public String getTargetId() {
30
        return targetId;
31
    }
32
33
    public void setTargetId(String targetId) {
34
        this.targetId = targetId;
35
    }
36
37
    public int getTargetType() {
38
        return targetType;
39
    }
40
41
    public void setTargetType(int targetType) {
42
        this.targetType = targetType;
43
    }
44
45
    public int getLevel() {
46
        return level;
47
    }
48
49
    public void setLevel(int level) {
50
        this.level = level;
51
    }
52
53
    public String getUserId() {
54
        return userId;
55
    }
56
57
    public void setUserId(String userId) {
58
        this.userId = userId;
59
    }
60
61
    public String getNickNameFromUser() {
62
        return nickNameFromUser;
63
    }
64
65
    public void setNickNameFromUser(String nickNameFromUser) {
66
        this.nickNameFromUser = nickNameFromUser;
67
    }
68
69
    public String getHeadImgFromUser() {
70
        return headImgFromUser;
71
    }
72
73
    public void setHeadImgFromUser(String headImgFromUser) {
74
        this.headImgFromUser = headImgFromUser;
75
    }
76
77
    public String getToUserId() {
78
        return toUserId;
79
    }
80
81
    public void setToUserId(String toUserId) {
82
        this.toUserId = toUserId;
83
    }
84
85
    public String getNickNameToUser() {
86
        return nickNameToUser;
87
    }
88
89
    public void setNickNameToUser(String nickNameToUser) {
90
        this.nickNameToUser = nickNameToUser;
91
    }
92
93
    public String getHeadImgToUser() {
94
        return headImgToUser;
95
    }
96
97
    public void setHeadImgToUser(String headImgToUser) {
98
        this.headImgToUser = headImgToUser;
99
    }
100
101
    public String getContent() {
102
        return content;
103
    }
104
105
    public void setContent(String content) {
106
        this.content = content;
107
    }
108
109
    public int getLikeNums() {
110
        return likeNums;
111
    }
112
113
    public void setLikeNums(int likeNums) {
114
        this.likeNums = likeNums;
115
    }
116
117
    public int getLikeFlg() {
118
        return likeFlg;
119
    }
120
121
    public void setLikeFlg(int likeFlg) {
122
        this.likeFlg = likeFlg;
123
    }
124
125
    public String getAddDate() {
126
        return addDate;
127
    }
128
129
    public void setAddDate(String addDate) {
130
        this.addDate = addDate;
131
    }
132
133
    public String getCommentsId() {
134
        return commentsId;
135
    }
136
137
    public void setCommentsId(String commentsId) {
138
        this.commentsId = commentsId;
139
    }
140
141
    public String getCommentsId2() {
142
        return commentsId2;
143
    }
144
145
    public void setCommentsId2(String commentsId2) {
146
        this.commentsId2 = commentsId2;
147
    }
148
149
    public String getUserId2() {
150
        return userId2;
151
    }
152
153
    public void setUserId2(String userId2) {
154
        this.userId2 = userId2;
155
    }
156
157
    public String getNickName2() {
158
        return nickName2;
159
    }
160
161
    public void setNickName2(String nickName2) {
162
        this.nickName2 = nickName2;
163
    }
164
165
    public String getContent2() {
166
        return content2;
167
    }
168
169
    public void setContent2(String content2) {
170
        this.content2 = content2;
171
    }
172
173
    public String getReplyNums() {
174
        return replyNums;
175
    }
176
177
    public void setReplyNums(String replyNums) {
178
        this.replyNums = replyNums;
179
    }
180
}

+ 37 - 0
app/src/main/java/com/electric/chargingpile/data/VideoDetailsBean.java

@ -0,0 +1,37 @@
1
package com.electric.chargingpile.data;
2
3
/**
4
 * Created by Demon on 16/11/22.
5
 */
6
7
public class VideoDetailsBean {
8
    private String targetId ="";
9
    private int targetType;
10
    private String videoUrl ="";
11
    private String coverImgUrl ="";
12
    private String authorName ="";
13
    private String authorHeadImg ="";
14
    private String authorId ="";
15
    private String title ="";
16
    private String publishDate_s ="";
17
    private String h5Url ="";
18
    private int likeNums;
19
20
    private int likeFlg;
21
    private int feedFlg;
22
    private int commentsNums;
23
    private int visitTimes;
24
25
    private int picsVos;
26
27
28
29
30
    public class Video{
31
32
    }
33
34
    public class Pic{
35
36
    }
37
}

+ 0 - 15
app/src/main/java/com/electric/chargingpile/fragment/QaActivityFragment.java

@ -1,42 +1,27 @@
1 1
package com.electric.chargingpile.fragment;
2 2
3 3
import android.Manifest;
4
import android.app.Activity;
5 4
import android.content.Context;
6 5
import android.content.Intent;
7
import android.content.SharedPreferences;
8 6
import android.os.Bundle;
9 7
import android.support.annotation.NonNull;
10 8
import android.support.v4.app.Fragment;
11
import android.support.v7.app.AppCompatActivity;
12 9
import android.util.Log;
13
import android.view.KeyEvent;
14 10
import android.view.LayoutInflater;
15 11
import android.view.View;
16 12
import android.view.ViewGroup;
17 13
import android.widget.AbsListView;
18 14
import android.widget.ImageView;
19
import android.widget.LinearLayout;
20 15
import android.widget.ListView;
21
import android.widget.RelativeLayout;
22
import android.widget.TextView;
23 16
import android.widget.Toast;
24 17
25
import com.blankj.utilcode.util.ActivityUtils;
26 18
import com.electric.chargingpile.R;
27 19
import com.electric.chargingpile.activity.EditQuestionOneActivity;
28
import com.electric.chargingpile.activity.FindActivity;
29 20
import com.electric.chargingpile.activity.LoginActivity;
30
import com.electric.chargingpile.activity.MainMapActivity;
31
import com.electric.chargingpile.activity.SearchQuestionActivity;
32 21
import com.electric.chargingpile.activity.TalkActivity;
33
import com.electric.chargingpile.activity.UnansweredActivity;
34
import com.electric.chargingpile.activity.UserCenterActivity;
35
import com.electric.chargingpile.adapter.QADataAdapter;
36 22
import com.electric.chargingpile.adapter.QADataFramAdapter;
37 23
import com.electric.chargingpile.application.MainApplication;
38 24
import com.electric.chargingpile.data.QAData;
39
import com.electric.chargingpile.manager.ProfileManager;
40 25
import com.electric.chargingpile.util.BarColorUtil;
41 26
import com.electric.chargingpile.util.JsonUtils;
42 27
import com.electric.chargingpile.util.ToastUtil;

+ 0 - 3
app/src/main/java/com/electric/chargingpile/fragment/QaZanFragment.java

@ -1,12 +1,9 @@
1 1
package com.electric.chargingpile.fragment;
2 2
3
import android.content.Context;
4
import android.net.Uri;
5 3
import android.os.Bundle;
6 4
import android.os.Handler;
7 5
import android.support.v4.app.Fragment;
8 6
import android.support.v4.widget.SwipeRefreshLayout;
9
import android.util.Log;
10 7
import android.view.LayoutInflater;
11 8
import android.view.View;
12 9
import android.view.ViewGroup;

+ 107 - 0
app/src/main/java/com/electric/chargingpile/fragment/ShortVideoFragment.java

@ -0,0 +1,107 @@
1
package com.electric.chargingpile.fragment;
2
3
4
import android.app.Activity;
5
import android.content.Context;
6
import android.os.Bundle;
7
import android.support.annotation.Nullable;
8
import android.support.v4.app.Fragment;
9
import android.support.v4.view.ViewPager;
10
import android.view.LayoutInflater;
11
import android.view.View;
12
import android.view.ViewGroup;
13
14
import com.electric.chargingpile.R;
15
import com.electric.chargingpile.adapter.SvVideoPagerAdapter;
16
import com.electric.chargingpile.view.sview.VerticalViewPager;
17
18
import java.util.ArrayList;
19
20
21
public class ShortVideoFragment extends Fragment implements ViewPager.OnPageChangeListener {
22
23
    //    private PullToRefreshLayout refresh_view;
24
    private VerticalViewPager pager_video;
25
26
    private SvVideoPagerAdapter viewPagerAdapter;
27
28
    private boolean isRefresh = true, isFirst = true, isChange = false;
29
    private boolean isHidden = false;
30
    private Activity activity;
31
32
    @Override
33
    public void onAttach(Context context) {
34
        super.onAttach(context);
35
        activity = (Activity) context;
36
    }
37
38
    @Nullable
39
    @Override
40
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
41
        return inflater.inflate(R.layout.fragment_shortvideo, container, false);
42
    }
43
44
    @Override
45
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
46
        super.onViewCreated(view, savedInstanceState);
47
48
//        refresh_view = view.findViewById(R.id.refresh_view);
49
        pager_video = view.findViewById(R.id.pager_video);
50
51
//        refresh_view.setOnRefreshListener(this);
52
        viewPagerAdapter = new SvVideoPagerAdapter(activity,
53
                new SvVideoShowView.OnDeleteVideoListener() {
54
                    @Override
55
                    public void onDelete() {
56
57
                    }
58
                });
59
        pager_video.setAdapter(viewPagerAdapter);
60
        pager_video.setOnPageChangeListener(this);
61
        addGetData();
62
    }
63
64
    private void deleteGetData() {
65
        pager_video.setAdapter(viewPagerAdapter);
66
        viewPagerAdapter.notifyChanged(null);
67
        pager_video.setCurrentItem(0);
68
        initPlayByPostion();
69
    }
70
71
    private void addGetData() {
72
        isFirst = true;
73
        viewPagerAdapter.notifyChanged(new ArrayList());
74
        getViewData();
75
    }
76
77
    private void getViewData() {
78
79
//        if (!isRefresh) {
80
//            refresh_view.loadmoreFinish(PullToRefreshLayout.SUCCEED);
81
//        } else {
82
//            refresh_view.refreshFinish(PullToRefreshLayout.SUCCEED);
83
//        }
84
        viewPagerAdapter.notifyChanged(null);
85
    }
86
87
    private void initPlayByPostion() {
88
    }
89
90
91
    @Override
92
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
93
94
    }
95
96
    @Override
97
    public void onPageSelected(int position) {
98
        if (!isChange) {
99
            isChange = true;
100
        }
101
    }
102
103
    @Override
104
    public void onPageScrollStateChanged(int state) {
105
106
    }
107
}

+ 186 - 0
app/src/main/java/com/electric/chargingpile/fragment/SvVideoShowView.java

@ -0,0 +1,186 @@
1
package com.electric.chargingpile.fragment;
2
3
import android.app.Activity;
4
import android.view.LayoutInflater;
5
import android.view.View;
6
import android.view.ViewGroup;
7
import android.widget.ImageView;
8
import android.widget.LinearLayout;
9
import android.widget.TextView;
10
import android.widget.Toast;
11
12
import com.electric.chargingpile.R;
13
import com.electric.chargingpile.application.MainApplication;
14
import com.electric.chargingpile.data.TalkRecommendBean;
15
import com.electric.chargingpile.data.VideoDetailsBean;
16
import com.electric.chargingpile.util.JsonUtils;
17
import com.electric.chargingpile.util.ToastUtil;
18
import com.zhy.http.okhttp.OkHttpUtils;
19
import com.zhy.http.okhttp.callback.StringCallback;
20
21
import java.util.HashMap;
22
import java.util.Map;
23
24
import okhttp3.Call;
25
26
public class SvVideoShowView {
27
28
    private Activity activity;
29
    private OnDeleteVideoListener listener;
30
    private View view;
31
    private ViewGroup viewGroup;
32
33
34
    private LinearLayout sv_show_forward, sv_show_comment_count_ll, sv_show_like_ll,
35
            sv_show_comment_ll, sv_show_topic;
36
    private TextView sv_show_comment_count_tv, sv_show_like_tv, sv_show_tvcon,
37
            sv_show_user_name, sv_show_user_time, sv_show_topic_con;
38
    private ImageView sv_show_like_img, sv_show_user_avatar;
39
40
    private View sv_show_tvcon_more;
41
42
43
    public SvVideoShowView(Activity activity, OnDeleteVideoListener listener) {
44
        this.activity = activity;
45
        this.listener = listener;
46
    }
47
48
    public void addView(ViewGroup container) {
49
        viewGroup = container;
50
    }
51
52
    public void setInfo(TalkRecommendBean talkRecommendBean) {
53
        int targetType = talkRecommendBean.targetType;
54
        if (targetType == 1) {
55
            view = LayoutInflater.from(activity).inflate(R.layout.view_show_view, null);
56
            initPlayer(view);
57
        } else {
58
            view = LayoutInflater.from(activity).inflate(R.layout.view_show_zoom, null);
59
            initZoomPhoto(view);
60
        }
61
        initBottom(view);
62
        viewGroup.addView(view);
63
        requestHeaderData(targetType, talkRecommendBean.targetId);
64
    }
65
66
    private void requestHeaderData(int targetType, long targetId) {
67
        String url = MainApplication.urlNew + "/article/detail";
68
        Map<String, String> map = new HashMap<>();
69
        map.put("targetType", targetType + "");
70
        map.put("targetId", targetId + "");
71
        if (MainApplication.isLogin()) {
72
            map.put("user_id", MainApplication.userId);
73
        }
74
75
        OkHttpUtils
76
                .get()
77
                .params(map)
78
                .url(url)
79
                .build()
80
                .connTimeOut(6000)
81
                .readTimeOut(6000)
82
                .execute(new StringCallback() {
83
                    @Override
84
                    public void onError(Call call, Exception e) {
85
                        ToastUtil.showToast(activity, "加载失败,请重试", Toast.LENGTH_SHORT);
86
                    }
87
88
                    @Override
89
                    public void onResponse(String response) {
90
                        String rtnCode = JsonUtils.getKeyResult(response, "code");
91
                        if ("1000".equals(rtnCode)) {
92
                            String rtnMsg = JsonUtils.getKeyResult(response, "data");
93
                            VideoDetailsBean qadata = (VideoDetailsBean) JsonUtils
94
                                    .parseToObjectList(rtnMsg, VideoDetailsBean.class);
95
                            setData(qadata);
96
                        }
97
                    }
98
                });
99
    }
100
101
    private void setData(VideoDetailsBean qadata) {
102
103
    }
104
105
    private void likeRequest(int targetType, int targetId, final int likeFlag, int authorId) {
106
        String url = MainApplication.urlNew + "/article/like";
107
        Map<String, String> map = new HashMap<>();
108
        map.put("targetType", targetType + "");
109
        map.put("targetId", targetId + "");
110
        map.put("flag", likeFlag + "");
111
        map.put("authorId", authorId + "");
112
        map.put("totalLikeCnt", "1");
113
        if (MainApplication.isLogin()) {
114
            map.put("user_id", MainApplication.userId);
115
        }
116
117
        OkHttpUtils
118
                .get()
119
                .params(map)
120
                .url(url)
121
                .build()
122
                .connTimeOut(6000)
123
                .readTimeOut(6000)
124
                .execute(new StringCallback() {
125
                    @Override
126
                    public void onError(Call call, Exception e) {
127
                        ToastUtil.showToast(activity, "请求失败,请重试", Toast.LENGTH_SHORT);
128
                    }
129
130
                    @Override
131
                    public void onResponse(String response) {
132
                        String rtnCode = JsonUtils.getKeyResult(response, "code");
133
                        if ("1000".equals(rtnCode)) {
134
                            if (likeFlag == 1) {
135
                                //点赞
136
                            } else {
137
                                //取消赞
138
                            }
139
                        }
140
                    }
141
                });
142
    }
143
144
145
    private void initBottom(View view) {
146
        sv_show_topic = view.findViewById(R.id.sv_show_topic);
147
        sv_show_forward = view.findViewById(R.id.sv_show_forward);
148
        sv_show_comment_count_ll = view.findViewById(R.id.sv_show_comment_count_ll);
149
        sv_show_like_ll = view.findViewById(R.id.sv_show_like_ll);
150
        sv_show_like_img = view.findViewById(R.id.sv_show_like_img);
151
        sv_show_like_tv = view.findViewById(R.id.sv_show_like_tv);
152
        sv_show_comment_ll = view.findViewById(R.id.sv_show_comment_ll);
153
        sv_show_comment_count_tv = view.findViewById(R.id.sv_show_comment_count_tv);
154
        sv_show_tvcon = view.findViewById(R.id.sv_show_tvcon);
155
156
        sv_show_tvcon_more = view.findViewById(R.id.sv_show_tvcon_more);
157
        sv_show_user_avatar = view.findViewById(R.id.sv_show_user_avatar);
158
        sv_show_user_name = view.findViewById(R.id.sv_show_user_name);
159
        sv_show_user_time = view.findViewById(R.id.sv_show_user_time);
160
        sv_show_topic_con = view.findViewById(R.id.sv_show_topic_con);
161
    }
162
163
    private void initPlayer(View view) {
164
165
    }
166
167
    private void initZoomPhoto(View view) {
168
169
    }
170
171
172
    public View getRootView() {
173
        return view;
174
    }
175
176
    public void updateView() {
177
    }
178
179
    public void initAndPlay() {
180
    }
181
182
183
    public interface OnDeleteVideoListener {
184
        void onDelete();
185
    }
186
}

+ 68 - 43
app/src/main/java/com/electric/chargingpile/fragment/TalkRecommendFragment.java

@ -20,6 +20,7 @@ import com.andview.refreshview.XRefreshView.SimpleXRefreshListener;
20 20
import com.andview.refreshview.XRefreshViewFooter;
21 21
import com.electric.chargingpile.R;
22 22
import com.electric.chargingpile.activity.PublishItemsActivity;
23
import com.electric.chargingpile.activity.VideoDetaislActivity;
23 24
import com.electric.chargingpile.activity.ZoomingPhotoTextActivity;
24 25
import com.electric.chargingpile.adapter.LayoutAdapter;
25 26
import com.electric.chargingpile.adapter.QADataFramAdapter;
@ -62,7 +63,7 @@ public class TalkRecommendFragment extends Fragment implements View.OnClickListe
62 63
        layoutAdapter = new LayoutAdapter(getActivity());
63 64
        // 设置静默加载模式
64 65
//		xRefreshView1.setSilenceLoadMore();
65
        layoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
66
        layoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
66 67
        recyclerView.setLayoutManager(layoutManager);
67 68
        // 静默加载模式不能设置footerview
68 69
        recyclerView.setAdapter(layoutAdapter);
@ -115,17 +116,40 @@ public class TalkRecommendFragment extends Fragment implements View.OnClickListe
115 116
        layoutAdapter.setOnRecyclerItemClickListener(new RecyclerItemTypeClickListener() {
116 117
            @Override
117 118
            public void onItemClickListener(int position, int type) {
118
                position--;
119
//                position--;
120
//                ArrayList<TalkRecommendBean> talkRecommendBeans = layoutAdapter.getCurrentData();
121
//                String targetId = talkRecommendBeans.get(position).targetId+"";
122
//                String targetType = talkRecommendBeans.get(position).targetType+"";
123
//                Intent intent = new Intent(getActivity(), ZoomingPhotoTextActivity.class);
124
//                intent.putExtra("targetId", targetId);
125
//                intent.putExtra("targetType", targetType);
126
//                startActivity(intent);
127
                int pos = position - 1;
128
                Intent intent = new Intent(getActivity(), VideoDetaislActivity.class);
119 129
                ArrayList<TalkRecommendBean> talkRecommendBeans = layoutAdapter.getCurrentData();
120
                String targetId = talkRecommendBeans.get(position).targetId+"";
121
                String targetType = talkRecommendBeans.get(position).targetType+"";
122
                Intent intent = new Intent(getActivity(), ZoomingPhotoTextActivity.class);
123
                intent.putExtra("targetId", targetId);
124
                intent.putExtra("targetType", targetType);
130
                intent.putExtra("list", talkRecommendBeans);
131
                intent.putExtra("pos", pos);
125 132
                startActivity(intent);
126 133
            }
127 134
        });
128 135
136
//        layoutAdapter.setOnItemClickListener(new LayoutAdapter.OnItemClickListener() {
137
//
138
//            @Override
139
//            public void onItemClick(View view) {
140
//                ArrayList<TalkRecommendBean> talkRecommendBeans = layoutAdapter.getCurrentData();
141
//
142
//                int pos = recyclerView.getChildAdapterPosition(view);
143
//                Toast.makeText(getContext(), talkRecommendBeans.get(pos).toString(), Toast.LENGTH_SHORT).show();
144
//                Intent intent = new Intent(getActivity(), VideoDetaislActivity.class);
145
//                intent.putExtra("list", talkRecommendBeans);
146
//                intent.putExtra("pos", pos);
147
//
148
//                startActivity(intent);
149
//
150
//            }
151
//        });
152
129 153
        initScrollListener();
130 154
131 155
        return view;
@ -136,12 +160,13 @@ public class TalkRecommendFragment extends Fragment implements View.OnClickListe
136 160
            @Override
137 161
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
138 162
                //当前状态为停止滑动状态SCROLL_STATE_IDLE时
139
                if(newState == RecyclerView.SCROLL_STATE_IDLE){
163
                if (newState == RecyclerView.SCROLL_STATE_IDLE) {
140 164
                    iv_ask.setVisibility(View.VISIBLE);
141
                }else if(newState == RecyclerView.SCREEN_STATE_ON){
165
                } else if (newState == RecyclerView.SCREEN_STATE_ON) {
142 166
                    iv_ask.setVisibility(View.GONE);
143 167
                }
144 168
            }
169
145 170
            @Override
146 171
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
147 172
            }
@ -166,7 +191,7 @@ public class TalkRecommendFragment extends Fragment implements View.OnClickListe
166 191
167 192
    @Override
168 193
    public void onClick(View v) {
169
        switch (v.getId()){
194
        switch (v.getId()) {
170 195
            case R.id.iv_ask:
171 196
                startActivity(new Intent(getActivity(), PublishItemsActivity.class));
172 197
//                Toast.makeText(getActivity(), "分享", Toast.LENGTH_SHORT).show();
@ -174,31 +199,31 @@ public class TalkRecommendFragment extends Fragment implements View.OnClickListe
174 199
        }
175 200
    }
176 201
177
    public void setBottomBtnEnableVisible(boolean isVisible){
178
        if(null == iv_ask)
202
    public void setBottomBtnEnableVisible(boolean isVisible) {
203
        if (null == iv_ask)
179 204
            return;
180
        if(isVisible)
205
        if (isVisible)
181 206
            iv_ask.setVisibility(View.VISIBLE);
182 207
        else
183 208
            iv_ask.setVisibility(View.GONE);
184 209
    }
185 210
186
    private void requestHeaderData(){
187
        String url = MainApplication.urlNew+"/topic/list.do";
211
    private void requestHeaderData() {
212
        String url = MainApplication.urlNew + "/topic/list.do";
188 213
//        Log.e(TAG, "getQAData: "+url );
189
        Map<String,String> map = new HashMap<>();
190
        map.put("page",page+"");
191
        if (MainApplication.isLogin()){
192
            map.put("user_id",MainApplication.userId);
214
        Map<String, String> map = new HashMap<>();
215
        map.put("page", page + "");
216
        if (MainApplication.isLogin()) {
217
            map.put("user_id", MainApplication.userId);
193 218
        }
194 219
        OkHttpUtils.get().params(map).url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
195 220
            @Override
196 221
            public void onError(Call call, Exception e) {
197
                if(page == 1)
222
                if (page == 1)
198 223
                    xRefreshView.stopRefresh();
199 224
                else
200 225
                    xRefreshView.setLoadComplete(true);
201
                ToastUtil.showToast(getActivity().getApplicationContext(),"加载失败,请重试",Toast.LENGTH_SHORT);
226
                ToastUtil.showToast(getActivity().getApplicationContext(), "加载失败,请重试", Toast.LENGTH_SHORT);
202 227
            }
203 228
204 229
            @Override
@ -208,11 +233,11 @@ public class TalkRecommendFragment extends Fragment implements View.OnClickListe
208 233
//                else
209 234
//                    xRefreshView.setLoadComplete(true);
210 235
211
                Log.e(TAG, "onResponse: "+response );
212
                String rtnCode = JsonUtils.getKeyResult(response,"code");
213
                if ("1000".equals(rtnCode)){
214
                    String rtnMsg = JsonUtils.getKeyResult(response,"data");
215
                    ArrayList <TalkRecommendBean> qadata = (ArrayList<TalkRecommendBean>) JsonUtils.parseToObjectList(rtnMsg,TalkRecommendBean.class);
236
                Log.e(TAG, "onResponse: " + response);
237
                String rtnCode = JsonUtils.getKeyResult(response, "code");
238
                if ("1000".equals(rtnCode)) {
239
                    String rtnMsg = JsonUtils.getKeyResult(response, "data");
240
                    ArrayList<TalkRecommendBean> qadata = (ArrayList<TalkRecommendBean>) JsonUtils.parseToObjectList(rtnMsg, TalkRecommendBean.class);
216 241
                    layoutAdapter.setHeaderData(qadata);
217 242
                    requestData();
218 243
                }
@ -220,43 +245,43 @@ public class TalkRecommendFragment extends Fragment implements View.OnClickListe
220 245
        });
221 246
    }
222 247
223
    private void requestData(){
224
        String url = MainApplication.urlNew+"/topic/info/list.do";
248
    private void requestData() {
249
        String url = MainApplication.urlNew + "/topic/info/list.do";
225 250
//        Log.e(TAG, "getQAData: "+url );
226
        Map<String,String> map = new HashMap<>();
227
        map.put("page",page+"");
228
        if (MainApplication.isLogin()){
229
            map.put("user_id",MainApplication.userId);
251
        Map<String, String> map = new HashMap<>();
252
        map.put("page", page + "");
253
        if (MainApplication.isLogin()) {
254
            map.put("user_id", MainApplication.userId);
230 255
        }
231 256
        OkHttpUtils.get().params(map).url(url).build().connTimeOut(6000).readTimeOut(6000).execute(new StringCallback() {
232 257
            @Override
233 258
            public void onError(Call call, Exception e) {
234
                if(page == 1)
259
                if (page == 1)
235 260
                    xRefreshView.stopRefresh();
236 261
                else
237 262
                    xRefreshView.setLoadComplete(true);
238
                ToastUtil.showToast(getActivity().getApplicationContext(),"加载失败,请重试",Toast.LENGTH_SHORT);
263
                ToastUtil.showToast(getActivity().getApplicationContext(), "加载失败,请重试", Toast.LENGTH_SHORT);
239 264
            }
240 265
241 266
            @Override
242 267
            public void onResponse(String response) {
243
                if(page == 1)
268
                if (page == 1)
244 269
                    xRefreshView.stopRefresh();
245 270
                else
246 271
                    xRefreshView.setLoadComplete(true);
247 272
248
                Log.e(TAG, "onResponse: "+response );
249
                String rtnCode = JsonUtils.getKeyResult(response,"code");
250
                if ("1000".equals(rtnCode)){
251
                    String rtnMsg = JsonUtils.getKeyResult(response,"data");
252
                    ArrayList <TalkRecommendBean> qadata = (ArrayList<TalkRecommendBean>) JsonUtils.parseToObjectList(rtnMsg,TalkRecommendBean.class);
253
                    if(page == 1)
273
                Log.e(TAG, "onResponse: " + response);
274
                String rtnCode = JsonUtils.getKeyResult(response, "code");
275
                if ("1000".equals(rtnCode)) {
276
                    String rtnMsg = JsonUtils.getKeyResult(response, "data");
277
                    ArrayList<TalkRecommendBean> qadata = (ArrayList<TalkRecommendBean>) JsonUtils.parseToObjectList(rtnMsg, TalkRecommendBean.class);
278
                    if (page == 1)
254 279
                        layoutAdapter.setData(qadata);
255 280
                    else
256 281
                        layoutAdapter.addData(qadata);
257
                    Log.e(TAG, "onResponse: qadata"+qadata.size() );
282
                    Log.e(TAG, "onResponse: qadata" + qadata.size());
258 283
//                    Log.e(TAG, "onResponse01: "+datas.size() );
259
                }else if ("02".equals(rtnCode)){
284
                } else if ("02".equals(rtnCode)) {
260 285
                    ToastUtil.showToast(getActivity().getApplicationContext(), "已经全部加载完毕", Toast.LENGTH_SHORT);
261 286
                }
262 287
            }

+ 2 - 0
app/src/main/java/com/electric/chargingpile/iview/RecyclerItemTypeClickListener.java

@ -6,4 +6,6 @@ package com.electric.chargingpile.iview;
6 6

7 7
public interface RecyclerItemTypeClickListener {
8 8
    void onItemClickListener(int position, int index);
9

10

9 11
}

+ 0 - 41
app/src/main/java/com/electric/chargingpile/view/AutoHeightViewPager.java

@ -1,41 +0,0 @@
1
package com.electric.chargingpile.view;
2
3
import android.content.Context;
4
import android.support.v4.view.ViewPager;
5
import android.util.AttributeSet;
6
import android.view.View;
7
8
/**
9
 * 自适应子View高度的viewPager
10
 * 
11
 * @author hellsam
12
 * 
13
 */
14
public class AutoHeightViewPager extends ViewPager {
15
16
	public AutoHeightViewPager(Context context, AttributeSet attrs) {
17
		super(context, attrs);
18
	}
19
20
	@Override
21
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
22
		int height = 0;
23
		// 下面遍历所有child的高度
24
		for (int i = 0; i < getChildCount(); i++) {
25
			View child = getChildAt(i);
26
			child.measure(widthMeasureSpec,
27
					MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
28
			int h = child.getMeasuredHeight();
29
			// 采用最大的view的高度
30
			if (h > height) {
31
				height = h;
32
			}
33
		}
34
35
		heightMeasureSpec = MeasureSpec.makeMeasureSpec(height,
36
				MeasureSpec.EXACTLY);
37
38
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
39
	}
40
41
}

+ 0 - 80
app/src/main/java/com/electric/chargingpile/view/AutoSplitTextView.java

@ -1,80 +0,0 @@
1
package com.electric.chargingpile.view;
2
3
import android.content.Context;
4
import android.graphics.Paint;
5
import android.text.TextUtils;
6
import android.util.AttributeSet;
7
import android.widget.TextView;
8
9
        public class AutoSplitTextView extends TextView {
10
     private boolean mEnabled = true;
11
12
          public AutoSplitTextView(Context context) {
13
                super(context);
14
            }
15
16
             public AutoSplitTextView(Context context, AttributeSet attrs) {
17
                 super(context, attrs);
18
            }
19
20
          public AutoSplitTextView(Context context, AttributeSet attrs, int defStyle) {
21
               super(context, attrs, defStyle);
22
          }
23
24
          public void setAutoSplitEnabled(boolean enabled) {
25
                mEnabled = enabled;
26
            }
27
28
             @Override
29
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
30
              if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY
31
                   && MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY
32
                  && getWidth() > 0
33
                 && getHeight() > 0
34
                   && mEnabled) {
35
                     String newText = autoSplitText(this);
36
                     if (!TextUtils.isEmpty(newText)) {
37
                               setText(newText);
38
                          }
39
                  }
40
               super.onMeasure(widthMeasureSpec, heightMeasureSpec);
41
           }
42
43
        private String autoSplitText(final TextView tv) {
44
       final String rawText = tv.getText().toString(); //原始文本
45
           final Paint tvPaint = tv.getPaint(); //paint,包含字体等信息
46
               final float tvWidth = tv.getWidth() - tv.getPaddingLeft() - tv.getPaddingRight(); //控件可用宽度
47
48
               //将原始文本按行拆分
49
               String [] rawTextLines = rawText.replaceAll("\r", "").split("\n");
50
              StringBuilder sbNewText = new StringBuilder();
51
               for (String rawTextLine : rawTextLines) {
52
                        if (tvPaint.measureText(rawTextLine) <= tvWidth) {
53
                             //如果整行宽度在控件可用宽度之内,就不处理了
54
                           sbNewText.append(rawTextLine);
55
                           } else {
56
                               //如果整行宽度超过控件可用宽度,则按字符测量,在超过可用宽度的前一个字符处手动换行
57
                               float lineWidth = 0;
58
                               for (int cnt = 0; cnt != rawTextLine.length(); ++cnt) {
59
                                      char ch = rawTextLine.charAt(cnt);
60
                                       lineWidth += tvPaint.measureText(String.valueOf(ch));
61
                                      if (lineWidth <= tvWidth) {
62
                                                 sbNewText.append(ch);
63
                                           } else {
64
                                               sbNewText.append("\n");
65
                                             lineWidth = 0;
66
                                                 --cnt;
67
                                            }
68
                                 }
69
                             }
70
                        sbNewText.append("\n");
71
                     }
72
73
                 //把结尾多余的\n去掉
74
               if (!rawText.endsWith("\n")) {
75
                         sbNewText.deleteCharAt(sbNewText.length() - 1);
76
                     }
77
78
                 return sbNewText.toString();
79
             }
80
 }

+ 0 - 216
app/src/main/java/com/electric/chargingpile/view/Dialog.java

@ -1,216 +0,0 @@
1
package com.electric.chargingpile.view;
2
3
import android.app.Activity;
4
import android.content.Context;
5
import android.content.res.Configuration;
6
import android.os.Handler;
7
import android.util.DisplayMetrics;
8
import android.view.Gravity;
9
import android.view.LayoutInflater;
10
import android.view.View;
11
import android.view.View.OnClickListener;
12
import android.view.Window;
13
import android.view.WindowManager;
14
import android.widget.LinearLayout;
15
import android.widget.LinearLayout.LayoutParams;
16
import android.widget.TextView;
17
18
import com.electric.chargingpile.R;
19
20
21
/**
22
 * 就是自定义的Dialog,不可back或点击外部销毁
23
 * @author liangshiquan
24
 *
25
 */
26
public class Dialog {
27
	public final static int SELECT_DIALOG=1;
28
	public final static int RADIO_DIALOG=2;
29
	/**
30
	 * 创建一个内容多选对话框
31
	 * @param context
32
	 * @param title	标题
33
	 * @param items 数组
34
	 * @param dialogItemClickListener 监听点击的内容结果
35
	 * @return
36
	 */
37
	public static android.app.Dialog showListDialog(Context context,String title,String[] items,final DialogItemClickListener dialogItemClickListener){
38
		return ShowDialog(context,title,items,dialogItemClickListener);
39
	}
40
	/**
41
	 * 创建一个单选对话框
42
	 * @param context
43
	 * @param toast 提示消息
44
	 * @param dialogClickListener 点击监听
45
	 * @return
46
	 */
47
	public static android.app.Dialog showRadioDialog(Context context,String toast,final DialogClickListener dialogClickListener){
48
		return ShowDialog(context,context.getResources().getString(R.string.pointMessage),toast,dialogClickListener,RADIO_DIALOG);
49
	}
50
	/**
51
	 * 创建一个选择对话框
52
	 * @param context
53
	 * @param toast 提示消息
54
	 * @param dialogClickListener 点击监听
55
	 * @return
56
	 */
57
	public static android.app.Dialog showSelectDialog(Context context,String toast,final DialogClickListener dialogClickListener){
58
		return ShowDialog(context,context.getResources().getString(R.string.pointMessage),toast,dialogClickListener,SELECT_DIALOG);
59
	}
60
	/**
61
	 * 创建一个选择对话框
62
	 * @param context
63
	 * @param title 提示标题
64
	 * @param toast 提示消息
65
	 * @param dialogClickListener 点击监听
66
	 * @return
67
	 */
68
	public static android.app.Dialog showSelectDialog(Context context,String title,String toast,final DialogClickListener dialogClickListener){
69
		return ShowDialog(context,title,toast,dialogClickListener,SELECT_DIALOG);
70
	}
71
	private static android.app.Dialog ShowDialog(Context context,String title,String toast,final DialogClickListener dialogClickListener,int DialogType){ 
72
		final android.app.Dialog dialog=new android.app.Dialog(context, R.style.DialogStyle);
73
		dialog.setCancelable(false);
74
		View view=LayoutInflater.from(context).inflate(R.layout.dialog, null);
75
		dialog.setContentView(view);
76
		((TextView)view.findViewById(R.id.point)).setText(title);
77
		((TextView)view.findViewById(R.id.toast)).setText(toast);
78
		if(DialogType==RADIO_DIALOG){
79
		}else{
80
			view.findViewById(R.id.ok).setVisibility(View.GONE);
81
			view.findViewById(R.id.divider).setVisibility(View.VISIBLE);
82
		}
83
		view.findViewById(R.id.cancel).setOnClickListener(new OnClickListener() {
84
			@Override
85
			public void onClick(View arg0) {
86
				dialog.dismiss();
87
				new Handler().postDelayed(new Runnable() {
88
					@Override
89
					public void run() {
90
						dialogClickListener.cancel();
91
					}
92
				},200);
93
			}
94
		});
95
		view.findViewById(R.id.confirm).setOnClickListener(new OnClickListener() {
96
			@Override
97
			public void onClick(View arg0) {
98
				dialog.dismiss();
99
				new Handler().postDelayed(new Runnable() {
100
					@Override
101
					public void run() {
102
						dialogClickListener.confirm();
103
					}
104
				},200);
105
			}
106
		});
107
		view.findViewById(R.id.ok).setOnClickListener(new OnClickListener() {
108
			@Override
109
			public void onClick(View arg0) {
110
				dialog.dismiss();
111
				new Handler().postDelayed(new Runnable() {
112
					@Override
113
					public void run() {
114
						dialogClickListener.confirm();
115
					}
116
				},200);
117
			}
118
		});
119
		Window mWindow=dialog.getWindow();
120
        WindowManager.LayoutParams lp = mWindow.getAttributes();
121
        if(context.getResources().getConfiguration().orientation==Configuration.ORIENTATION_LANDSCAPE){//横屏
122
            lp.width= getScreenHeight(context)/10*8;
123
        }else{
124
            lp.width= getScreenWidth(context)/10*8;
125
        }
126
        mWindow.setAttributes(lp);
127
		dialog.show();
128
		
129
		return dialog;
130
	}
131
	private static android.app.Dialog ShowDialog(Context context,String title,String[] items,final DialogItemClickListener dialogClickListener){ 
132
		final android.app.Dialog dialog=new android.app.Dialog(context, R.style.DialogStyle);
133
		dialog.setCancelable(false);
134
		View view=LayoutInflater.from(context).inflate(R.layout.dialog_radio, null);
135
		dialog.setContentView(view);
136
		((TextView)view.findViewById(R.id.title)).setText(title);
137
		//根据items动态创建
138
		LinearLayout parent=(LinearLayout) view.findViewById(R.id.dialogLayout);
139
		parent.removeAllViews();
140
		int length=items.length;
141
		for (int i = 0; i < items.length; i++) {
142
			LayoutParams params1=new LayoutParams(-1,-2);
143
			params1.rightMargin=1;
144
			final TextView tv=new TextView(context);
145
			tv.setLayoutParams(params1);
146
			tv.setTextSize(18);
147
			tv.setText(items[i]);
148
			tv.setTextColor(context.getResources().getColor(R.color.dialogTxtColor));
149
			int pad=context.getResources().getDimensionPixelSize(R.dimen.padding10);
150
			tv.setPadding(pad,pad,pad,pad);
151
			tv.setSingleLine(true);
152
			tv.setGravity(Gravity.CENTER);
153
			if(i!=length-1)
154
				tv.setBackgroundResource(R.drawable.menudialog_center_selector);
155
			else
156
				tv.setBackgroundResource(R.drawable.menudialog_bottom2_selector);
157
				
158
			tv.setOnClickListener(new OnClickListener() {
159
				@Override
160
				public void onClick(View arg0) {
161
					dialog.dismiss();
162
					dialogClickListener.confirm(tv.getText().toString());
163
				}
164
			});
165
			parent.addView(tv);
166
			if(i!=length-1){
167
				TextView divider=new TextView(context);
168
				LayoutParams params=new LayoutParams(-1,(int)1);
169
				divider.setLayoutParams(params);
170
				divider.setBackgroundResource(android.R.color.darker_gray);
171
				parent.addView(divider);
172
			}
173
		}
174
		view.findViewById(R.id.ok).setOnClickListener(new OnClickListener() {
175
			@Override
176
			public void onClick(View arg0) {
177
				dialog.dismiss();
178
			}
179
		});
180
		Window mWindow=dialog.getWindow();
181
		WindowManager.LayoutParams lp = mWindow.getAttributes();
182
	    lp.width= getScreenWidth(context);
183
		mWindow.setGravity(Gravity.BOTTOM);
184
		//添加动画
185
		mWindow.setWindowAnimations(R.style.dialogAnim);
186
		mWindow.setAttributes(lp);
187
		dialog.show();
188
		return dialog;
189
	}
190
	/**获取屏幕分辨率宽*/
191
	public static int getScreenWidth(Context context) {
192
		DisplayMetrics dm = new DisplayMetrics();
193
		try {
194
195
			((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
196
197
		} catch (Exception e) {
198
			e.printStackTrace();
199
		}
200
		return dm.widthPixels;
201
	}
202
203
	/**获取屏幕分辨率高*/
204
	public static int getScreenHeight(Context context){
205
		DisplayMetrics dm = new DisplayMetrics();
206
		((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(dm);
207
        return dm.heightPixels;
208
	}
209
	public interface DialogClickListener{
210
		public abstract void confirm();
211
		public abstract void cancel();
212
	}
213
	public interface DialogItemClickListener{
214
		public abstract void confirm(String result);
215
	}
216
}

+ 194 - 0
app/src/main/java/com/electric/chargingpile/view/VideoCommentDialog.java

@ -0,0 +1,194 @@
1
package com.electric.chargingpile.view;
2
3
import android.app.Dialog;
4
import android.content.Context;
5
import android.os.Bundle;
6
import android.support.v7.widget.RecyclerView;
7
import android.text.TextUtils;
8
import android.view.Gravity;
9
import android.view.LayoutInflater;
10
import android.view.View;
11
import android.view.Window;
12
import android.view.WindowManager;
13
import android.widget.EditText;
14
import android.widget.ImageView;
15
import android.widget.LinearLayout;
16
import android.widget.ListView;
17
import android.widget.TextView;
18
import android.widget.Toast;
19
20
import com.electric.chargingpile.R;
21
import com.electric.chargingpile.adapter.VideoCommentAdapter;
22
import com.electric.chargingpile.application.MainApplication;
23
import com.electric.chargingpile.data.TalkRecommendBean;
24
import com.electric.chargingpile.data.VideoCommentBean;
25
import com.electric.chargingpile.util.JsonUtils;
26
import com.electric.chargingpile.util.ToastUtil;
27
import com.zhy.http.okhttp.OkHttpUtils;
28
import com.zhy.http.okhttp.callback.StringCallback;
29
30
import java.util.ArrayList;
31
import java.util.HashMap;
32
import java.util.Map;
33
34
import okhttp3.Call;
35
36
public class VideoCommentDialog extends Dialog implements View.OnClickListener {
37
    private Context context;
38
39
    private TextView showCommentTitle;
40
    private View showCommentClose;
41
    private RecyclerView showCommentLv;
42
    private EditText showCommentEd;
43
    private TextView showCommentPublish;
44
45
    private VideoCommentAdapter videoCommentAdapter;
46
47
48
    public VideoCommentDialog(Context context) {
49
        super(context, R.style.bottomDialogStyle);
50
        this.context = context;
51
    }
52
53
54
    @Override
55
    protected void onCreate(Bundle savedInstanceState) {
56
        super.onCreate(savedInstanceState);
57
        View inflate = LayoutInflater.from(context).inflate(R.layout.view_show_comment, null);
58
        initView(inflate);
59
        setContentView(inflate);
60
61
62
        Window window = this.getWindow();
63
        window.setGravity(Gravity.BOTTOM);
64
        WindowManager.LayoutParams params = window.getAttributes();
65
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
66
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
67
        window.setAttributes(params);
68
69
    }
70
71
    public void setComment(int targetType, int targetId, final int commentId) {
72
73
        String url = MainApplication.urlNew + "/article/like";
74
        Map<String, String> map = new HashMap<>();
75
        map.put("targetType", targetType + "");
76
        map.put("targetId", targetId + "");
77
        map.put("flag", commentId + "");
78
79
        if (MainApplication.isLogin()) {
80
            map.put("user_id", MainApplication.userId);
81
        }
82
83
        OkHttpUtils
84
                .get()
85
                .params(map)
86
                .url(url)
87
                .build()
88
                .connTimeOut(6000)
89
                .readTimeOut(6000)
90
                .execute(new StringCallback() {
91
                    @Override
92
                    public void onError(Call call, Exception e) {
93
                        if (commentId == 0) {
94
95
                        } else {
96
                            ToastUtil.showToast(context, "请求失败,请重试", Toast.LENGTH_SHORT);
97
                        }
98
                    }
99
100
                    @Override
101
                    public void onResponse(String response) {
102
                        String rtnCode = JsonUtils.getKeyResult(response, "code");
103
                        if ("1000".equals(rtnCode)) {
104
                            String rtnMsg = JsonUtils.getKeyResult(response, "data");
105
                            ArrayList<VideoCommentBean> qadata = (ArrayList<VideoCommentBean>) JsonUtils.parseToObjectList(rtnMsg, VideoCommentBean.class);
106
                            if (videoCommentAdapter != null) {
107
                                if (commentId == 0) {
108
                                    videoCommentAdapter.cleanData();
109
                                }
110
                                videoCommentAdapter.addData(qadata);
111
                            }
112
                        }
113
                    }
114
                });
115
    }
116
117
118
    private void initView(View convertView) {
119
120
        showCommentTitle = (TextView) convertView.findViewById(R.id.show_comment_title);
121
        showCommentClose = (View) convertView.findViewById(R.id.show_comment_close);
122
        showCommentLv = (RecyclerView) convertView.findViewById(R.id.show_comment_lv);
123
        showCommentEd = (EditText) convertView.findViewById(R.id.show_comment_ed);
124
        showCommentPublish = (TextView) convertView.findViewById(R.id.show_comment_publish);
125
126
        videoCommentAdapter = new VideoCommentAdapter(context);
127
        showCommentLv.setAdapter(videoCommentAdapter);
128
129
        showCommentClose.setOnClickListener(this);
130
        showCommentPublish.setOnClickListener(this);
131
    }
132
133
    @Override
134
    public void onClick(View view) {
135
        switch (view.getId()) {
136
            case R.id.show_comment_close:
137
                dismiss();
138
                break;
139
            case R.id.show_comment_publish:
140
                String commentCon = showCommentEd.getText().toString();
141
                if (TextUtils.isEmpty(commentCon)) {
142
                    Toast.makeText(context, "请输入评论内容!", Toast.LENGTH_SHORT).show();
143
                    return;
144
                }
145
//                publishComment(commentCon);
146
                break;
147
            default:
148
                break;
149
        }
150
    }
151
152
    private void publishComment(String commentCon, int targetId, int targetType, String toUserId,
153
                                String parentId, int level, String toCommentIds) {
154
        String url = MainApplication.urlNew + "/comments/publish";
155
        Map<String, String> map = new HashMap<>();
156
        map.put("targetType", targetType + "");
157
        map.put("targetId", targetId + "");
158
        map.put("toUserId", toUserId);
159
        map.put("parentId", parentId);
160
        map.put("level", level + "");
161
        map.put("toCommentIds", toCommentIds);
162
        map.put("commentCon", commentCon);
163
164
        if (MainApplication.isLogin()) {
165
            map.put("user_id", MainApplication.userId);
166
        }
167
168
        OkHttpUtils
169
                .get()
170
                .params(map)
171
                .url(url)
172
                .build()
173
                .connTimeOut(6000)
174
                .readTimeOut(6000)
175
                .execute(new StringCallback() {
176
                    @Override
177
                    public void onError(Call call, Exception e) {
178
                        ToastUtil.showToast(context, "请求失败,请重试", Toast.LENGTH_SHORT);
179
                    }
180
181
                    @Override
182
                    public void onResponse(String response) {
183
                        String rtnCode = JsonUtils.getKeyResult(response, "code");
184
                        if ("1000".equals(rtnCode)) {
185
                            String rtnMsg = JsonUtils.getKeyResult(response, "data");
186
                            ArrayList<VideoCommentBean> qadata = (ArrayList<VideoCommentBean>) JsonUtils.parseToObjectList(rtnMsg, VideoCommentBean.class);
187
                            if (videoCommentAdapter != null) {
188
                                videoCommentAdapter.addData(qadata);
189
                            }
190
                        }
191
                    }
192
                });
193
    }
194
}

+ 66 - 0
app/src/main/java/com/electric/chargingpile/view/VideoPubilshDialog.java

@ -0,0 +1,66 @@
1
package com.electric.chargingpile.view;
2
3
import android.app.Dialog;
4
import android.content.Context;
5
import android.os.Bundle;
6
import android.view.Gravity;
7
import android.view.LayoutInflater;
8
import android.view.View;
9
import android.view.Window;
10
import android.view.WindowManager;
11
import android.widget.ImageView;
12
import android.widget.LinearLayout;
13
import android.widget.TextView;
14
15
import com.electric.chargingpile.R;
16
17
public class VideoPubilshDialog extends Dialog implements View.OnClickListener {
18
    private Context context;
19
20
    public VideoPubilshDialog(Context context) {
21
        super(context, R.style.bottomDialogStyle);
22
        this.context = context;
23
    }
24
25
    private View videoPublishClose;
26
    private LinearLayout videoPublishTopic;
27
    private TextView videoPublishTopicCon;
28
    private LinearLayout videoPublishUserLl;
29
    private ImageView videoPublishUserAvatar;
30
    private TextView videoPublishUserName;
31
32
    @Override
33
    protected void onCreate(Bundle savedInstanceState) {
34
        super.onCreate(savedInstanceState);
35
        View inflate = LayoutInflater.from(context).inflate(R.layout.sv_video_publish_info, null);
36
37
        videoPublishClose = inflate.findViewById(R.id.video_publish_close);
38
        videoPublishTopic = inflate.findViewById(R.id.video_publish_topic);
39
        videoPublishTopicCon = inflate.findViewById(R.id.video_publish_topic_con);
40
        videoPublishUserLl = inflate.findViewById(R.id.video_publish_user_ll);
41
        videoPublishUserAvatar = inflate.findViewById(R.id.video_publish_user_avatar);
42
        videoPublishUserName = inflate.findViewById(R.id.video_publish_user_name);
43
44
        videoPublishClose.setOnClickListener(this);
45
46
        setContentView(inflate);
47
48
49
        Window window = this.getWindow();
50
        window.setGravity(Gravity.BOTTOM);
51
        WindowManager.LayoutParams params = window.getAttributes();
52
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
53
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
54
        window.setAttributes(params);
55
56
    }
57
58
    @Override
59
    public void onClick(View view) {
60
        switch (view.getId()) {
61
            case R.id.video_publish_close:
62
                dismiss();
63
                break;
64
        }
65
    }
66
}

+ 28 - 0
app/src/main/java/com/electric/chargingpile/view/sview/SvHomeViewPager.java

@ -0,0 +1,28 @@
1
package com.electric.chargingpile.view.sview;
2
3
import android.content.Context;
4
import android.support.v4.view.ViewPager;
5
import android.util.AttributeSet;
6
7
8
public class SvHomeViewPager extends ViewPager {
9
    private boolean isCanScroll = true;
10
    public SvHomeViewPager(Context context) {
11
        super(context);
12
    }
13
14
    public SvHomeViewPager(Context context, AttributeSet attrs) {
15
        super(context, attrs);
16
    }
17
    public void setScanScroll(boolean isCanScroll){
18
        this.isCanScroll = isCanScroll;
19
    }
20
21
22
    @Override
23
    public void scrollTo(int x, int y){
24
        if (isCanScroll){
25
            super.scrollTo(x, y);
26
        }
27
    }
28
}

+ 2791 - 0
app/src/main/java/com/electric/chargingpile/view/sview/VerticalViewPager.java

@ -0,0 +1,2791 @@
1
package com.electric.chargingpile.view.sview;
2
3
import android.content.Context;
4
import android.content.res.Resources;
5
import android.content.res.TypedArray;
6
import android.database.DataSetObserver;
7
import android.graphics.Canvas;
8
import android.graphics.Rect;
9
import android.graphics.drawable.Drawable;
10
import android.os.Build;
11
import android.os.Bundle;
12
import android.os.Parcel;
13
import android.os.Parcelable;
14
import android.os.SystemClock;
15
import android.support.v4.os.ParcelableCompat;
16
import android.support.v4.os.ParcelableCompatCreatorCallbacks;
17
import android.support.v4.view.AccessibilityDelegateCompat;
18
import android.support.v4.view.MotionEventCompat;
19
import android.support.v4.view.PagerAdapter;
20
import android.support.v4.view.VelocityTrackerCompat;
21
import android.support.v4.view.ViewCompat;
22
import android.support.v4.view.ViewConfigurationCompat;
23
import android.support.v4.view.ViewPager;
24
import android.support.v4.view.accessibility.AccessibilityEventCompat;
25
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
26
import android.support.v4.view.accessibility.AccessibilityRecordCompat;
27
import android.support.v4.widget.EdgeEffectCompat;
28
import android.util.AttributeSet;
29
import android.util.Log;
30
import android.view.FocusFinder;
31
import android.view.Gravity;
32
import android.view.KeyEvent;
33
import android.view.MotionEvent;
34
import android.view.SoundEffectConstants;
35
import android.view.VelocityTracker;
36
import android.view.View;
37
import android.view.ViewConfiguration;
38
import android.view.ViewGroup;
39
import android.view.ViewParent;
40
import android.view.accessibility.AccessibilityEvent;
41
import android.view.animation.Interpolator;
42
import android.widget.Scroller;
43
44
import java.lang.reflect.Method;
45
import java.util.ArrayList;
46
import java.util.Collections;
47
import java.util.Comparator;
48
49
/**
50
 * Created by castorflex on 12/29/13.
51
 * Just a copy of the original ViewPager modified to support vertical Scrolling
52
 */
53
public class VerticalViewPager extends ViewGroup {
54
55
    private static final String TAG = "ViewPager";
56
    private static final boolean DEBUG = false;
57
58
    private static final boolean USE_CACHE = false;
59
60
    private static final int DEFAULT_OFFSCREEN_PAGES = 1;
61
    private static final int MAX_SETTLE_DURATION = 600; // ms
62
    private static final int MIN_DISTANCE_FOR_FLING = 25; // dips
63
64
    private static final int DEFAULT_GUTTER_SIZE = 16; // dips
65
66
    private static final int MIN_FLING_VELOCITY = 400; // dips
67
68
    private static final int[] LAYOUT_ATTRS = new int[]{
69
            android.R.attr.layout_gravity
70
    };
71
72
    /**
73
     * Used to track what the expected number of items in the adapter should be.
74
     * If the app changes this when we don't expect it, we'll throw a big obnoxious exception.
75
     */
76
    private int mExpectedAdapterCount;
77
78
    static class ItemInfo {
79
        Object object;
80
        int position;
81
        boolean scrolling;
82
        float heightFactor;
83
        float offset;
84
    }
85
86
    private static final Comparator<ItemInfo> COMPARATOR = new Comparator<ItemInfo>() {
87
        @Override
88
        public int compare(ItemInfo lhs, ItemInfo rhs) {
89
            return lhs.position - rhs.position;
90
        }
91
    };
92
93
    private static final Interpolator sInterpolator = new Interpolator() {
94
        public float getInterpolation(float t) {
95
            t -= 1.0f;
96
            return t * t * t * t * t + 1.0f;
97
        }
98
    };
99
100
    private final ArrayList<ItemInfo> mItems = new ArrayList<ItemInfo>();
101
    private final ItemInfo mTempItem = new ItemInfo();
102
103
    private final Rect mTempRect = new Rect();
104
105
    private PagerAdapter mAdapter;
106
    private int mCurItem;   // Index of currently displayed page.
107
    private int mRestoredCurItem = -1;
108
    private Parcelable mRestoredAdapterState = null;
109
    private ClassLoader mRestoredClassLoader = null;
110
    private Scroller mScroller;
111
    private PagerObserver mObserver;
112
113
    private int mPageMargin;
114
    private Drawable mMarginDrawable;
115
    private int mLeftPageBounds;
116
    private int mRightPageBounds;
117
118
    // Offsets of the first and last items, if known.
119
    // Set during population, used to determine if we are at the beginning
120
    // or end of the pager data set during touch scrolling.
121
    private float mFirstOffset = -Float.MAX_VALUE;
122
    private float mLastOffset = Float.MAX_VALUE;
123
124
    private int mChildWidthMeasureSpec;
125
    private int mChildHeightMeasureSpec;
126
    private boolean mInLayout;
127
128
    private boolean mScrollingCacheEnabled;
129
130
    private boolean mPopulatePending;
131
    private int mOffscreenPageLimit = DEFAULT_OFFSCREEN_PAGES;
132
133
    private boolean mIsBeingDragged;
134
    private boolean mIsUnableToDrag;
135
    private boolean mIgnoreGutter;
136
    private int mDefaultGutterSize;
137
    private int mGutterSize;
138
    private int mTouchSlop;
139
    /**
140
     * Position of the last motion event.
141
     */
142
    private float mLastMotionX;
143
    private float mLastMotionY;
144
    private float mInitialMotionX;
145
    private float mInitialMotionY;
146
    /**
147
     * ID of the active pointer. This is used to retain consistency during
148
     * drags/flings if multiple pointers are used.
149
     */
150
    private int mActivePointerId = INVALID_POINTER;
151
    /**
152
     * Sentinel value for no current active pointer.
153
     * Used by {@link #mActivePointerId}.
154
     */
155
    private static final int INVALID_POINTER = -1;
156
157
    /**
158
     * Determines speed during touch scrolling
159
     */
160
    private VelocityTracker mVelocityTracker;
161
    private int mMinimumVelocity;
162
    private int mMaximumVelocity;
163
    private int mFlingDistance;
164
    private int mCloseEnough;
165
166
    // If the pager is at least this close to its final position, complete the scroll
167
    // on touch down and let the user interact with the content inside instead of
168
    // "catching" the flinging pager.
169
    private static final int CLOSE_ENOUGH = 2; // dp
170
171
    private boolean mFakeDragging;
172
    private long mFakeDragBeginTime;
173
174
    private EdgeEffectCompat mTopEdge;
175
    private EdgeEffectCompat mBottomEdge;
176
177
    private boolean mFirstLayout = true;
178
    private boolean mNeedCalculatePageOffsets = false;
179
    private boolean mCalledSuper;
180
    private int mDecorChildCount;
181
182
    private ViewPager.OnPageChangeListener mOnPageChangeListener;
183
    private ViewPager.OnPageChangeListener mInternalPageChangeListener;
184
    private OnAdapterChangeListener mAdapterChangeListener;
185
    private ViewPager.PageTransformer mPageTransformer;
186
    private Method mSetChildrenDrawingOrderEnabled;
187
188
    private static final int DRAW_ORDER_DEFAULT = 0;
189
    private static final int DRAW_ORDER_FORWARD = 1;
190
    private static final int DRAW_ORDER_REVERSE = 2;
191
    private int mDrawingOrder;
192
    private ArrayList<View> mDrawingOrderedChildren;
193
    private static final ViewPositionComparator sPositionComparator = new ViewPositionComparator();
194
195
    /**
196
     * Indicates that the pager is in an idle, settled state. The current page
197
     * is fully in view and no animation is in progress.
198
     */
199
    public static final int SCROLL_STATE_IDLE = 0;
200
201
    /**
202
     * Indicates that the pager is currently being dragged by the user.
203
     */
204
    public static final int SCROLL_STATE_DRAGGING = 1;
205
206
    /**
207
     * Indicates that the pager is in the process of settling to a final position.
208
     */
209
    public static final int SCROLL_STATE_SETTLING = 2;
210
211
    private final Runnable mEndScrollRunnable = new Runnable() {
212
        @Override
213
        public void run() {
214
            setScrollState(SCROLL_STATE_IDLE);
215
            populate();
216
        }
217
    };
218
219
    private int mScrollState = SCROLL_STATE_IDLE;
220
221
    /**
222
     * Used internally to monitor when adapters are switched.
223
     */
224
    interface OnAdapterChangeListener {
225
        public void onAdapterChanged(PagerAdapter oldAdapter, PagerAdapter newAdapter);
226
    }
227
228
    /**
229
     * Used internally to tag special types of child views that should be added as
230
     * pager decorations by default.
231
     */
232
    interface Decor {
233
    }
234
235
    public VerticalViewPager(Context context) {
236
        super(context);
237
        initViewPager();
238
    }
239
240
    public VerticalViewPager(Context context, AttributeSet attrs) {
241
        super(context, attrs);
242
        initViewPager();
243
    }
244
245
    void initViewPager() {
246
        setWillNotDraw(false);
247
        setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
248
        setFocusable(true);
249
        final Context context = getContext();
250
        mScroller = new Scroller(context, sInterpolator);
251
        final ViewConfiguration configuration = ViewConfiguration.get(context);
252
        final float density = context.getResources().getDisplayMetrics().density;
253
254
        mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
255
        mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density);
256
        mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
257
        mTopEdge = new EdgeEffectCompat(context);
258
        mBottomEdge = new EdgeEffectCompat(context);
259
260
        mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
261
        mCloseEnough = (int) (CLOSE_ENOUGH * density);
262
        mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);
263
264
        ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate());
265
266
        if (ViewCompat.getImportantForAccessibility(this)
267
                == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
268
            ViewCompat.setImportantForAccessibility(this,
269
                    ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
270
        }
271
    }
272
273
    @Override
274
    protected void onDetachedFromWindow() {
275
        removeCallbacks(mEndScrollRunnable);
276
        super.onDetachedFromWindow();
277
    }
278
279
    private void setScrollState(int newState) {
280
        if (mScrollState == newState) {
281
            return;
282
        }
283
284
        mScrollState = newState;
285
        if (mPageTransformer != null) {
286
            // PageTransformers can do complex things that benefit from hardware layers.
287
            enableLayers(newState != SCROLL_STATE_IDLE);
288
        }
289
        if (mOnPageChangeListener != null) {
290
            mOnPageChangeListener.onPageScrollStateChanged(newState);
291
        }
292
    }
293
294
    /**
295
     * Set a PagerAdapter that will supply views for this pager as needed.
296
     *
297
     * @param adapter Adapter to use
298
     */
299
    public void setAdapter(PagerAdapter adapter) {
300
        if (mAdapter != null) {
301
            mAdapter.unregisterDataSetObserver(mObserver);
302
            mAdapter.startUpdate(this);
303
            for (int i = 0; i < mItems.size(); i++) {
304
                final ItemInfo ii = mItems.get(i);
305
                mAdapter.destroyItem(this, ii.position, ii.object);
306
            }
307
            mAdapter.finishUpdate(this);
308
            mItems.clear();
309
            removeNonDecorViews();
310
            mCurItem = 0;
311
            scrollTo(0, 0);
312
        }
313
314
        final PagerAdapter oldAdapter = mAdapter;
315
        mAdapter = adapter;
316
        mExpectedAdapterCount = 0;
317
318
        if (mAdapter != null) {
319
            if (mObserver == null) {
320
                mObserver = new PagerObserver();
321
            }
322
            mAdapter.registerDataSetObserver(mObserver);
323
            mPopulatePending = false;
324
            final boolean wasFirstLayout = mFirstLayout;
325
            mFirstLayout = true;
326
            mExpectedAdapterCount = mAdapter.getCount();
327
            if (mRestoredCurItem >= 0) {
328
                mAdapter.restoreState(mRestoredAdapterState, mRestoredClassLoader);
329
                setCurrentItemInternal(mRestoredCurItem, false, true);
330
                mRestoredCurItem = -1;
331
                mRestoredAdapterState = null;
332
                mRestoredClassLoader = null;
333
            } else if (!wasFirstLayout) {
334
                populate();
335
            } else {
336
                requestLayout();
337
            }
338
        }
339
340
        if (mAdapterChangeListener != null && oldAdapter != adapter) {
341
            mAdapterChangeListener.onAdapterChanged(oldAdapter, adapter);
342
        }
343
    }
344
345
    private void removeNonDecorViews() {
346
        for (int i = 0; i < getChildCount(); i++) {
347
            final View child = getChildAt(i);
348
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
349
            if (!lp.isDecor) {
350
                removeViewAt(i);
351
                i--;
352
            }
353
        }
354
    }
355
356
    /**
357
     * Retrieve the current adapter supplying pages.
358
     *
359
     * @return The currently registered PagerAdapter
360
     */
361
    public PagerAdapter getAdapter() {
362
        return mAdapter;
363
    }
364
365
    void setOnAdapterChangeListener(OnAdapterChangeListener listener) {
366
        mAdapterChangeListener = listener;
367
    }
368
369
//    private int getClientWidth() {
370
//        return getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
371
//    }
372
373
    private int getClientHeight() {
374
        return getMeasuredHeight() - getPaddingTop() - getPaddingBottom();
375
    }
376
377
378
    /**
379
     * Set the currently selected page. If the ViewPager has already been through its first
380
     * layout with its current adapter there will be a smooth animated transition between
381
     * the current item and the specified item.
382
     *
383
     * @param item Item index to select
384
     */
385
    public void setCurrentItem(int item) {
386
        mPopulatePending = false;
387
        setCurrentItemInternal(item, !mFirstLayout, false);
388
    }
389
390
    /**
391
     * Set the currently selected page.
392
     *
393
     * @param item         Item index to select
394
     * @param smoothScroll True to smoothly scroll to the new item, false to transition immediately
395
     */
396
    public void setCurrentItem(int item, boolean smoothScroll) {
397
        mPopulatePending = false;
398
        setCurrentItemInternal(item, smoothScroll, false);
399
    }
400
401
    public int getCurrentItem() {
402
        return mCurItem;
403
    }
404
405
    void setCurrentItemInternal(int item, boolean smoothScroll, boolean always) {
406
        setCurrentItemInternal(item, smoothScroll, always, 0);
407
    }
408
409
    void setCurrentItemInternal(int item, boolean smoothScroll, boolean always, int velocity) {
410
        if (mAdapter == null || mAdapter.getCount() <= 0) {
411
            setScrollingCacheEnabled(false);
412
            return;
413
        }
414
        if (!always && mCurItem == item && mItems.size() != 0) {
415
            setScrollingCacheEnabled(false);
416
            return;
417
        }
418
419
        if (item < 0) {
420
            item = 0;
421
        } else if (item >= mAdapter.getCount()) {
422
            item = mAdapter.getCount() - 1;
423
        }
424
        final int pageLimit = mOffscreenPageLimit;
425
        if (item > (mCurItem + pageLimit) || item < (mCurItem - pageLimit)) {
426
            // We are doing a jump by more than one page.  To avoid
427
            // glitches, we want to keep all current pages in the view
428
            // until the scroll ends.
429
            for (int i = 0; i < mItems.size(); i++) {
430
                mItems.get(i).scrolling = true;
431
            }
432
        }
433
        final boolean dispatchSelected = mCurItem != item;
434
435
        if (mFirstLayout) {
436
            // We don't have any idea how big we are yet and shouldn't have any pages either.
437
            // Just set things up and let the pending layout handle things.
438
            mCurItem = item;
439
            if (dispatchSelected && mOnPageChangeListener != null) {
440
                mOnPageChangeListener.onPageSelected(item);
441
            }
442
            if (dispatchSelected && mInternalPageChangeListener != null) {
443
                mInternalPageChangeListener.onPageSelected(item);
444
            }
445
            requestLayout();
446
        } else {
447
            populate(item);
448
            scrollToItem(item, smoothScroll, velocity, dispatchSelected);
449
        }
450
    }
451
452
    private void scrollToItem(int item, boolean smoothScroll, int velocity,
453
                              boolean dispatchSelected) {
454
        final ItemInfo curInfo = infoForPosition(item);
455
        int destY = 0;
456
        if (curInfo != null) {
457
            final int height = getClientHeight();
458
            destY = (int) (height * Math.max(mFirstOffset,
459
                    Math.min(curInfo.offset, mLastOffset)));
460
        }
461
        if (smoothScroll) {
462
            smoothScrollTo(0, destY, velocity);
463
            if (dispatchSelected && mOnPageChangeListener != null) {
464
                mOnPageChangeListener.onPageSelected(item);
465
            }
466
            if (dispatchSelected && mInternalPageChangeListener != null) {
467
                mInternalPageChangeListener.onPageSelected(item);
468
            }
469
        } else {
470
            if (dispatchSelected && mOnPageChangeListener != null) {
471
                mOnPageChangeListener.onPageSelected(item);
472
            }
473
            if (dispatchSelected && mInternalPageChangeListener != null) {
474
                mInternalPageChangeListener.onPageSelected(item);
475
            }
476
            completeScroll(false);
477
            scrollTo(0, destY);
478
            pageScrolled(destY);
479
        }
480
    }
481
482
    /**
483
     * Set a listener that will be invoked whenever the page changes or is incrementally
484
     * scrolled. See {@link ViewPager.OnPageChangeListener}.
485
     *
486
     * @param listener Listener to set
487
     */
488
    public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
489
        mOnPageChangeListener = listener;
490
    }
491
492
    /**
493
     * Set a {@link ViewPager.PageTransformer} that will be called for each attached page whenever
494
     * the scroll position is changed. This allows the application to apply custom property
495
     * transformations to each page, overriding the default sliding look and feel.
496
     * <p/>
497
     * <p><em>Note:</em> Prior to Android 3.0 the property animation APIs did not exist.
498
     * As a result, setting a PageTransformer prior to Android 3.0 (API 11) will have no effect.</p>
499
     *
500
     * @param reverseDrawingOrder true if the supplied PageTransformer requires page views
501
     *                            to be drawn from last to first instead of first to last.
502
     * @param transformer         PageTransformer that will modify each page's animation properties
503
     */
504
    public void setPageTransformer(boolean reverseDrawingOrder, ViewPager.PageTransformer transformer) {
505
        if (Build.VERSION.SDK_INT >= 11) {
506
            final boolean hasTransformer = transformer != null;
507
            final boolean needsPopulate = hasTransformer != (mPageTransformer != null);
508
            mPageTransformer = transformer;
509
            setChildrenDrawingOrderEnabledCompat(hasTransformer);
510
            if (hasTransformer) {
511
                mDrawingOrder = reverseDrawingOrder ? DRAW_ORDER_REVERSE : DRAW_ORDER_FORWARD;
512
            } else {
513
                mDrawingOrder = DRAW_ORDER_DEFAULT;
514
            }
515
            if (needsPopulate) populate();
516
        }
517
    }
518
519
    void setChildrenDrawingOrderEnabledCompat(boolean enable) {
520
        if (Build.VERSION.SDK_INT >= 7) {
521
            if (mSetChildrenDrawingOrderEnabled == null) {
522
                try {
523
                    mSetChildrenDrawingOrderEnabled = ViewGroup.class.getDeclaredMethod(
524
                            "setChildrenDrawingOrderEnabled", new Class[]{Boolean.TYPE});
525
                } catch (NoSuchMethodException e) {
526
                    Log.e(TAG, "Can't find setChildrenDrawingOrderEnabled", e);
527
                }
528
            }
529
            try {
530
                mSetChildrenDrawingOrderEnabled.invoke(this, enable);
531
            } catch (Exception e) {
532
                Log.e(TAG, "Error changing children drawing order", e);
533
            }
534
        }
535
    }
536
537
    @Override
538
    protected int getChildDrawingOrder(int childCount, int i) {
539
        final int index = mDrawingOrder == DRAW_ORDER_REVERSE ? childCount - 1 - i : i;
540
        final int result = ((LayoutParams) mDrawingOrderedChildren.get(index).getLayoutParams()).childIndex;
541
        return result;
542
    }
543
544
    /**
545
     * Set a separate OnPageChangeListener for internal use by the support library.
546
     *
547
     * @param listener Listener to set
548
     * @return The old listener that was set, if any.
549
     */
550
    ViewPager.OnPageChangeListener setInternalPageChangeListener(ViewPager.OnPageChangeListener listener) {
551
        ViewPager.OnPageChangeListener oldListener = mInternalPageChangeListener;
552
        mInternalPageChangeListener = listener;
553
        return oldListener;
554
    }
555
556
    /**
557
     * Returns the number of pages that will be retained to either side of the
558
     * current page in the view hierarchy in an idle state. Defaults to 1.
559
     *
560
     * @return How many pages will be kept offscreen on either side
561
     * @see #setOffscreenPageLimit(int)
562
     */
563
    public int getOffscreenPageLimit() {
564
        return mOffscreenPageLimit;
565
    }
566
567
    /**
568
     * Set the number of pages that should be retained to either side of the
569
     * current page in the view hierarchy in an idle state. Pages beyond this
570
     * limit will be recreated from the adapter when needed.
571
     * <p/>
572
     * <p>This is offered as an optimization. If you know in advance the number
573
     * of pages you will need to support or have lazy-loading mechanisms in place
574
     * on your pages, tweaking this setting can have benefits in perceived smoothness
575
     * of paging animations and interaction. If you have a small number of pages (3-4)
576
     * that you can keep active all at once, less time will be spent in layout for
577
     * newly created view subtrees as the user pages back and forth.</p>
578
     * <p/>
579
     * <p>You should keep this limit low, especially if your pages have complex layouts.
580
     * This setting defaults to 1.</p>
581
     *
582
     * @param limit How many pages will be kept offscreen in an idle state.
583
     */
584
    public void setOffscreenPageLimit(int limit) {
585
        if (limit < DEFAULT_OFFSCREEN_PAGES) {
586
            Log.w(TAG, "Requested offscreen page limit " + limit + " too small; defaulting to " +
587
                    DEFAULT_OFFSCREEN_PAGES);
588
            limit = DEFAULT_OFFSCREEN_PAGES;
589
        }
590
        if (limit != mOffscreenPageLimit) {
591
            mOffscreenPageLimit = limit;
592
            populate();
593
        }
594
    }
595
596
    /**
597
     * Set the margin between pages.
598
     *
599
     * @param marginPixels Distance between adjacent pages in pixels
600
     * @see #getPageMargin()
601
     * @see #setPageMarginDrawable(Drawable)
602
     * @see #setPageMarginDrawable(int)
603
     */
604
    public void setPageMargin(int marginPixels) {
605
        final int oldMargin = mPageMargin;
606
        mPageMargin = marginPixels;
607
608
        final int height = getHeight();
609
        recomputeScrollPosition(height, height, marginPixels, oldMargin);
610
611
        requestLayout();
612
    }
613
614
    /**
615
     * Return the margin between pages.
616
     *
617
     * @return The size of the margin in pixels
618
     */
619
    public int getPageMargin() {
620
        return mPageMargin;
621
    }
622
623
    /**
624
     * Set a drawable that will be used to fill the margin between pages.
625
     *
626
     * @param d Drawable to display between pages
627
     */
628
    public void setPageMarginDrawable(Drawable d) {
629
        mMarginDrawable = d;
630
        if (d != null) refreshDrawableState();
631
        setWillNotDraw(d == null);
632
        invalidate();
633
    }
634
635
    /**
636
     * Set a drawable that will be used to fill the margin between pages.
637
     *
638
     * @param resId Resource ID of a drawable to display between pages
639
     */
640
    public void setPageMarginDrawable(int resId) {
641
        setPageMarginDrawable(getContext().getResources().getDrawable(resId));
642
    }
643
644
    @Override
645
    protected boolean verifyDrawable(Drawable who) {
646
        return super.verifyDrawable(who) || who == mMarginDrawable;
647
    }
648
649
    @Override
650
    protected void drawableStateChanged() {
651
        super.drawableStateChanged();
652
        final Drawable d = mMarginDrawable;
653
        if (d != null && d.isStateful()) {
654
            d.setState(getDrawableState());
655
        }
656
    }
657
658
    // We want the duration of the page snap animation to be influenced by the distance that
659
    // the screen has to travel, however, we don't want this duration to be effected in a
660
    // purely linear fashion. Instead, we use this method to moderate the effect that the distance
661
    // of travel has on the overall snap duration.
662
    float distanceInfluenceForSnapDuration(float f) {
663
        f -= 0.5f; // center the values about 0.
664
        f *= 0.3f * Math.PI / 2.0f;
665
        return (float) Math.sin(f);
666
    }
667
668
    /**
669
     * Like {@link View#scrollBy}, but scroll smoothly instead of immediately.
670
     *
671
     * @param x the number of pixels to scroll by on the X axis
672
     * @param y the number of pixels to scroll by on the Y axis
673
     */
674
    void smoothScrollTo(int x, int y) {
675
        smoothScrollTo(x, y, 0);
676
    }
677
678
    /**
679
     * Like {@link View#scrollBy}, but scroll smoothly instead of immediately.
680
     *
681
     * @param x        the number of pixels to scroll by on the X axis
682
     * @param y        the number of pixels to scroll by on the Y axis
683
     * @param velocity the velocity associated with a fling, if applicable. (0 otherwise)
684
     */
685
    void smoothScrollTo(int x, int y, int velocity) {
686
        if (getChildCount() == 0) {
687
            // Nothing to do.
688
            setScrollingCacheEnabled(false);
689
            return;
690
        }
691
        int sx = getScrollX();
692
        int sy = getScrollY();
693
        int dx = x - sx;
694
        int dy = y - sy;
695
        if (dx == 0 && dy == 0) {
696
            completeScroll(false);
697
            populate();
698
            setScrollState(SCROLL_STATE_IDLE);
699
            return;
700
        }
701
702
        setScrollingCacheEnabled(true);
703
        setScrollState(SCROLL_STATE_SETTLING);
704
705
        final int height = getClientHeight();
706
        final int halfHeight = height / 2;
707
        final float distanceRatio = Math.min(1f, 1.0f * Math.abs(dx) / height);
708
        final float distance = halfHeight + halfHeight *
709
                distanceInfluenceForSnapDuration(distanceRatio);
710
711
        int duration = 0;
712
        velocity = Math.abs(velocity);
713
        if (velocity > 0) {
714
            duration = 4 * Math.round(1000 * Math.abs(distance / velocity));
715
        } else {
716
            final float pageHeight = height * mAdapter.getPageWidth(mCurItem);
717
            final float pageDelta = (float) Math.abs(dx) / (pageHeight + mPageMargin);
718
            duration = (int) ((pageDelta + 1) * 100);
719
        }
720
        duration = Math.min(duration, MAX_SETTLE_DURATION);
721
722
        mScroller.startScroll(sx, sy, dx, dy, duration);
723
        ViewCompat.postInvalidateOnAnimation(this);
724
    }
725
726
    ItemInfo addNewItem(int position, int index) {
727
        ItemInfo ii = new ItemInfo();
728
        ii.position = position;
729
        ii.object = mAdapter.instantiateItem(this, position);
730
        ii.heightFactor = mAdapter.getPageWidth(position);
731
        if (index < 0 || index >= mItems.size()) {
732
            mItems.add(ii);
733
        } else {
734
            mItems.add(index, ii);
735
        }
736
        return ii;
737
    }
738
739
    void dataSetChanged() {
740
        // This method only gets called if our observer is attached, so mAdapter is non-null.
741
742
        final int adapterCount = mAdapter.getCount();
743
        mExpectedAdapterCount = adapterCount;
744
        boolean needPopulate = mItems.size() < mOffscreenPageLimit * 2 + 1 &&
745
                mItems.size() < adapterCount;
746
        int newCurrItem = mCurItem;
747
748
        boolean isUpdating = false;
749
        for (int i = 0; i < mItems.size(); i++) {
750
            final ItemInfo ii = mItems.get(i);
751
            final int newPos = mAdapter.getItemPosition(ii.object);
752
753
            if (newPos == PagerAdapter.POSITION_UNCHANGED) {
754
                continue;
755
            }
756
757
            if (newPos == PagerAdapter.POSITION_NONE) {
758
                mItems.remove(i);
759
                i--;
760
761
                if (!isUpdating) {
762
                    mAdapter.startUpdate(this);
763
                    isUpdating = true;
764
                }
765
766
                mAdapter.destroyItem(this, ii.position, ii.object);
767
                needPopulate = true;
768
769
                if (mCurItem == ii.position) {
770
                    // Keep the current item in the valid range
771
                    newCurrItem = Math.max(0, Math.min(mCurItem, adapterCount - 1));
772
                    needPopulate = true;
773
                }
774
                continue;
775
            }
776
777
            if (ii.position != newPos) {
778
                if (ii.position == mCurItem) {
779
                    // Our current item changed position. Follow it.
780
                    newCurrItem = newPos;
781
                }
782
783
                ii.position = newPos;
784
                needPopulate = true;
785
            }
786
        }
787
788
        if (isUpdating) {
789
            mAdapter.finishUpdate(this);
790
        }
791
792
        Collections.sort(mItems, COMPARATOR);
793
794
        if (needPopulate) {
795
            // Reset our known page widths; populate will recompute them.
796
            final int childCount = getChildCount();
797
            for (int i = 0; i < childCount; i++) {
798
                final View child = getChildAt(i);
799
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
800
                if (!lp.isDecor) {
801
                    lp.heightFactor = 0.f;
802
                }
803
            }
804
805
            setCurrentItemInternal(newCurrItem, false, true);
806
            requestLayout();
807
        }
808
    }
809
810
    void populate() {
811
        populate(mCurItem);
812
    }
813
814
    void populate(int newCurrentItem) {
815
        ItemInfo oldCurInfo = null;
816
        int focusDirection = View.FOCUS_FORWARD;
817
        if (mCurItem != newCurrentItem) {
818
            focusDirection = mCurItem < newCurrentItem ? View.FOCUS_DOWN : View.FOCUS_UP;
819
            oldCurInfo = infoForPosition(mCurItem);
820
            mCurItem = newCurrentItem;
821
        }
822
823
        if (mAdapter == null) {
824
            sortChildDrawingOrder();
825
            return;
826
        }
827
828
        // Bail now if we are waiting to populate.  This is to hold off
829
        // on creating views from the time the user releases their finger to
830
        // fling to a new position until we have finished the scroll to
831
        // that position, avoiding glitches from happening at that point.
832
        if (mPopulatePending) {
833
            if (DEBUG) {
834
                Log.i(TAG, "populate is pending, skipping for now...");
835
            }
836
            sortChildDrawingOrder();
837
            return;
838
        }
839
840
        // Also, don't populate until we are attached to a window.  This is to
841
        // avoid trying to populate before we have restored our view hierarchy
842
        // state and conflicting with what is restored.
843
        if (getWindowToken() == null) {
844
            return;
845
        }
846
847
        mAdapter.startUpdate(this);
848
849
        final int pageLimit = mOffscreenPageLimit;
850
        final int startPos = Math.max(0, mCurItem - pageLimit);
851
        final int N = mAdapter.getCount();
852
        final int endPos = Math.min(N - 1, mCurItem + pageLimit);
853
854
        if (N != mExpectedAdapterCount) {
855
            String resName;
856
            try {
857
                resName = getResources().getResourceName(getId());
858
            } catch (Resources.NotFoundException e) {
859
                resName = Integer.toHexString(getId());
860
            }
861
            throw new IllegalStateException("The application's PagerAdapter changed the adapter's" +
862
                    " contents without calling PagerAdapter#notifyDataSetChanged!" +
863
                    " Expected adapter item count: " + mExpectedAdapterCount + ", found: " + N +
864
                    " Pager id: " + resName +
865
                    " Pager class: " + getClass() +
866
                    " Problematic adapter: " + mAdapter.getClass());
867
        }
868
869
        // Locate the currently focused item or add it if needed.
870
        int curIndex = -1;
871
        ItemInfo curItem = null;
872
        for (curIndex = 0; curIndex < mItems.size(); curIndex++) {
873
            final ItemInfo ii = mItems.get(curIndex);
874
            if (ii.position >= mCurItem) {
875
                if (ii.position == mCurItem) curItem = ii;
876
                break;
877
            }
878
        }
879
880
        if (curItem == null && N > 0) {
881
            curItem = addNewItem(mCurItem, curIndex);
882
        }
883
884
        // Fill 3x the available width or up to the number of offscreen
885
        // pages requested to either side, whichever is larger.
886
        // If we have no current item we have no work to do.
887
        if (curItem != null) {
888
            float extraHeightTop = 0.f;
889
            int itemIndex = curIndex - 1;
890
            ItemInfo ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
891
            final int clientHeight = getClientHeight();
892
            final float topHeightNeeded = clientHeight <= 0 ? 0 :
893
                    2.f - curItem.heightFactor + (float) getPaddingLeft() / (float) clientHeight;
894
            for (int pos = mCurItem - 1; pos >= 0; pos--) {
895
                if (extraHeightTop >= topHeightNeeded && pos < startPos) {
896
                    if (ii == null) {
897
                        break;
898
                    }
899
                    if (pos == ii.position && !ii.scrolling) {
900
                        mItems.remove(itemIndex);
901
                        mAdapter.destroyItem(this, pos, ii.object);
902
                        if (DEBUG) {
903
                            Log.i(TAG, "populate() - destroyItem() with pos: " + pos +
904
                                    " view: " + ((View) ii.object));
905
                        }
906
                        itemIndex--;
907
                        curIndex--;
908
                        ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
909
                    }
910
                } else if (ii != null && pos == ii.position) {
911
                    extraHeightTop += ii.heightFactor;
912
                    itemIndex--;
913
                    ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
914
                } else {
915
                    ii = addNewItem(pos, itemIndex + 1);
916
                    extraHeightTop += ii.heightFactor;
917
                    curIndex++;
918
                    ii = itemIndex >= 0 ? mItems.get(itemIndex) : null;
919
                }
920
            }
921
922
            float extraHeightBottom = curItem.heightFactor;
923
            itemIndex = curIndex + 1;
924
            if (extraHeightBottom < 2.f) {
925
                ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
926
                final float bottomHeightNeeded = clientHeight <= 0 ? 0 :
927
                        (float) getPaddingRight() / (float) clientHeight + 2.f;
928
                for (int pos = mCurItem + 1; pos < N; pos++) {
929
                    if (extraHeightBottom >= bottomHeightNeeded && pos > endPos) {
930
                        if (ii == null) {
931
                            break;
932
                        }
933
                        if (pos == ii.position && !ii.scrolling) {
934
                            mItems.remove(itemIndex);
935
                            mAdapter.destroyItem(this, pos, ii.object);
936
                            if (DEBUG) {
937
                                Log.i(TAG, "populate() - destroyItem() with pos: " + pos +
938
                                        " view: " + ((View) ii.object));
939
                            }
940
                            ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
941
                        }
942
                    } else if (ii != null && pos == ii.position) {
943
                        extraHeightBottom += ii.heightFactor;
944
                        itemIndex++;
945
                        ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
946
                    } else {
947
                        ii = addNewItem(pos, itemIndex);
948
                        itemIndex++;
949
                        extraHeightBottom += ii.heightFactor;
950
                        ii = itemIndex < mItems.size() ? mItems.get(itemIndex) : null;
951
                    }
952
                }
953
            }
954
955
            calculatePageOffsets(curItem, curIndex, oldCurInfo);
956
        }
957
958
        if (DEBUG) {
959
            Log.i(TAG, "Current page list:");
960
            for (int i = 0; i < mItems.size(); i++) {
961
                Log.i(TAG, "#" + i + ": page " + mItems.get(i).position);
962
            }
963
        }
964
965
        mAdapter.setPrimaryItem(this, mCurItem, curItem != null ? curItem.object : null);
966
967
        mAdapter.finishUpdate(this);
968
969
        // Check width measurement of current pages and drawing sort order.
970
        // Update LayoutParams as needed.
971
        final int childCount = getChildCount();
972
        for (int i = 0; i < childCount; i++) {
973
            final View child = getChildAt(i);
974
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
975
            lp.childIndex = i;
976
            if (!lp.isDecor && lp.heightFactor == 0.f) {
977
                // 0 means requery the adapter for this, it doesn't have a valid width.
978
                final ItemInfo ii = infoForChild(child);
979
                if (ii != null) {
980
                    lp.heightFactor = ii.heightFactor;
981
                    lp.position = ii.position;
982
                }
983
            }
984
        }
985
        sortChildDrawingOrder();
986
987
        if (hasFocus()) {
988
            View currentFocused = findFocus();
989
            ItemInfo ii = currentFocused != null ? infoForAnyChild(currentFocused) : null;
990
            if (ii == null || ii.position != mCurItem) {
991
                for (int i = 0; i < getChildCount(); i++) {
992
                    View child = getChildAt(i);
993
                    ii = infoForChild(child);
994
                    if (ii != null && ii.position == mCurItem) {
995
                        if (child.requestFocus(focusDirection)) {
996
                            break;
997
                        }
998
                    }
999
                }
1000
            }
1001
        }
1002
    }
1003
1004
    private void sortChildDrawingOrder() {
1005
        if (mDrawingOrder != DRAW_ORDER_DEFAULT) {
1006
            if (mDrawingOrderedChildren == null) {
1007
                mDrawingOrderedChildren = new ArrayList<View>();
1008
            } else {
1009
                mDrawingOrderedChildren.clear();
1010
            }
1011
            final int childCount = getChildCount();
1012
            for (int i = 0; i < childCount; i++) {
1013
                final View child = getChildAt(i);
1014
                mDrawingOrderedChildren.add(child);
1015
            }
1016
            Collections.sort(mDrawingOrderedChildren, sPositionComparator);
1017
        }
1018
    }
1019
1020
    private void calculatePageOffsets(ItemInfo curItem, int curIndex, ItemInfo oldCurInfo) {
1021
        final int N = mAdapter.getCount();
1022
        final int height = getClientHeight();
1023
        final float marginOffset = height > 0 ? (float) mPageMargin / height : 0;
1024
        // Fix up offsets for later layout.
1025
        if (oldCurInfo != null) {
1026
            final int oldCurPosition = oldCurInfo.position;
1027
            // Base offsets off of oldCurInfo.
1028
            if (oldCurPosition < curItem.position) {
1029
                int itemIndex = 0;
1030
                ItemInfo ii = null;
1031
                float offset = oldCurInfo.offset + oldCurInfo.heightFactor + marginOffset;
1032
                for (int pos = oldCurPosition + 1;
1033
                     pos <= curItem.position && itemIndex < mItems.size(); pos++) {
1034
                    ii = mItems.get(itemIndex);
1035
                    while (pos > ii.position && itemIndex < mItems.size() - 1) {
1036
                        itemIndex++;
1037
                        ii = mItems.get(itemIndex);
1038
                    }
1039
                    while (pos < ii.position) {
1040
                        // We don't have an item populated for this,
1041
                        // ask the adapter for an offset.
1042
                        offset += mAdapter.getPageWidth(pos) + marginOffset;
1043
                        pos++;
1044
                    }
1045
                    ii.offset = offset;
1046
                    offset += ii.heightFactor + marginOffset;
1047
                }
1048
            } else if (oldCurPosition > curItem.position) {
1049
                int itemIndex = mItems.size() - 1;
1050
                ItemInfo ii = null;
1051
                float offset = oldCurInfo.offset;
1052
                for (int pos = oldCurPosition - 1;
1053
                     pos >= curItem.position && itemIndex >= 0; pos--) {
1054
                    ii = mItems.get(itemIndex);
1055
                    while (pos < ii.position && itemIndex > 0) {
1056
                        itemIndex--;
1057
                        ii = mItems.get(itemIndex);
1058
                    }
1059
                    while (pos > ii.position) {
1060
                        // We don't have an item populated for this,
1061
                        // ask the adapter for an offset.
1062
                        offset -= mAdapter.getPageWidth(pos) + marginOffset;
1063
                        pos--;
1064
                    }
1065
                    offset -= ii.heightFactor + marginOffset;
1066
                    ii.offset = offset;
1067
                }
1068
            }
1069
        }
1070
1071
        // Base all offsets off of curItem.
1072
        final int itemCount = mItems.size();
1073
        float offset = curItem.offset;
1074
        int pos = curItem.position - 1;
1075
        mFirstOffset = curItem.position == 0 ? curItem.offset : -Float.MAX_VALUE;
1076
        mLastOffset = curItem.position == N - 1 ?
1077
                curItem.offset + curItem.heightFactor - 1 : Float.MAX_VALUE;
1078
        // Previous pages
1079
        for (int i = curIndex - 1; i >= 0; i--, pos--) {
1080
            final ItemInfo ii = mItems.get(i);
1081
            while (pos > ii.position) {
1082
                offset -= mAdapter.getPageWidth(pos--) + marginOffset;
1083
            }
1084
            offset -= ii.heightFactor + marginOffset;
1085
            ii.offset = offset;
1086
            if (ii.position == 0) {
1087
                mFirstOffset = offset;
1088
            }
1089
        }
1090
        offset = curItem.offset + curItem.heightFactor + marginOffset;
1091
        pos = curItem.position + 1;
1092
        // Next pages
1093
        for (int i = curIndex + 1; i < itemCount; i++, pos++) {
1094
            final ItemInfo ii = mItems.get(i);
1095
            while (pos < ii.position) {
1096
                offset += mAdapter.getPageWidth(pos++) + marginOffset;
1097
            }
1098
            if (ii.position == N - 1) {
1099
                mLastOffset = offset + ii.heightFactor - 1;
1100
            }
1101
            ii.offset = offset;
1102
            offset += ii.heightFactor + marginOffset;
1103
        }
1104
1105
        mNeedCalculatePageOffsets = false;
1106
    }
1107
1108
    /**
1109
     * This is the persistent state that is saved by ViewPager.  Only needed
1110
     * if you are creating a sublass of ViewPager that must save its own
1111
     * state, in which case it should implement a subclass of this which
1112
     * contains that state.
1113
     */
1114
    public static class SavedState extends BaseSavedState {
1115
        int position;
1116
        Parcelable adapterState;
1117
        ClassLoader loader;
1118
1119
        public SavedState(Parcelable superState) {
1120
            super(superState);
1121
        }
1122
1123
        @Override
1124
        public void writeToParcel(Parcel out, int flags) {
1125
            super.writeToParcel(out, flags);
1126
            out.writeInt(position);
1127
            out.writeParcelable(adapterState, flags);
1128
        }
1129
1130
        @Override
1131
        public String toString() {
1132
            return "FragmentPager.SavedState{"
1133
                    + Integer.toHexString(System.identityHashCode(this))
1134
                    + " position=" + position + "}";
1135
        }
1136
1137
        public static final Creator<SavedState> CREATOR
1138
                = ParcelableCompat.newCreator(new ParcelableCompatCreatorCallbacks<SavedState>() {
1139
            @Override
1140
            public SavedState createFromParcel(Parcel in, ClassLoader loader) {
1141
                return new SavedState(in, loader);
1142
            }
1143
1144
            @Override
1145
            public SavedState[] newArray(int size) {
1146
                return new SavedState[size];
1147
            }
1148
        });
1149
1150
        SavedState(Parcel in, ClassLoader loader) {
1151
            super(in);
1152
            if (loader == null) {
1153
                loader = getClass().getClassLoader();
1154
            }
1155
            position = in.readInt();
1156
            adapterState = in.readParcelable(loader);
1157
            this.loader = loader;
1158
        }
1159
    }
1160
1161
    @Override
1162
    public Parcelable onSaveInstanceState() {
1163
        Parcelable superState = super.onSaveInstanceState();
1164
        SavedState ss = new SavedState(superState);
1165
        ss.position = mCurItem;
1166
        if (mAdapter != null) {
1167
            ss.adapterState = mAdapter.saveState();
1168
        }
1169
        return ss;
1170
    }
1171
1172
    @Override
1173
    public void onRestoreInstanceState(Parcelable state) {
1174
        if (!(state instanceof SavedState)) {
1175
            super.onRestoreInstanceState(state);
1176
            return;
1177
        }
1178
1179
        SavedState ss = (SavedState) state;
1180
        super.onRestoreInstanceState(ss.getSuperState());
1181
1182
        if (mAdapter != null) {
1183
            mAdapter.restoreState(ss.adapterState, ss.loader);
1184
            setCurrentItemInternal(ss.position, false, true);
1185
        } else {
1186
            mRestoredCurItem = ss.position;
1187
            mRestoredAdapterState = ss.adapterState;
1188
            mRestoredClassLoader = ss.loader;
1189
        }
1190
    }
1191
1192
    @Override
1193
    public void addView(View child, int index, ViewGroup.LayoutParams params) {
1194
        if (!checkLayoutParams(params)) {
1195
            params = generateLayoutParams(params);
1196
        }
1197
        final LayoutParams lp = (LayoutParams) params;
1198
        lp.isDecor |= child instanceof Decor;
1199
        if (mInLayout) {
1200
            if (lp != null && lp.isDecor) {
1201
                throw new IllegalStateException("Cannot add pager decor view during layout");
1202
            }
1203
            lp.needsMeasure = true;
1204
            addViewInLayout(child, index, params);
1205
        } else {
1206
            super.addView(child, index, params);
1207
        }
1208
1209
        if (USE_CACHE) {
1210
            if (child.getVisibility() != GONE) {
1211
                child.setDrawingCacheEnabled(mScrollingCacheEnabled);
1212
            } else {
1213
                child.setDrawingCacheEnabled(false);
1214
            }
1215
        }
1216
    }
1217
1218
    @Override
1219
    public void removeView(View view) {
1220
        if (mInLayout) {
1221
            removeViewInLayout(view);
1222
        } else {
1223
            super.removeView(view);
1224
        }
1225
    }
1226
1227
    ItemInfo infoForChild(View child) {
1228
        for (int i = 0; i < mItems.size(); i++) {
1229
            ItemInfo ii = mItems.get(i);
1230
            if (mAdapter.isViewFromObject(child, ii.object)) {
1231
                return ii;
1232
            }
1233
        }
1234
        return null;
1235
    }
1236
1237
    ItemInfo infoForAnyChild(View child) {
1238
        ViewParent parent;
1239
        while ((parent = child.getParent()) != this) {
1240
            if (parent == null || !(parent instanceof View)) {
1241
                return null;
1242
            }
1243
            child = (View) parent;
1244
        }
1245
        return infoForChild(child);
1246
    }
1247
1248
    ItemInfo infoForPosition(int position) {
1249
        for (int i = 0; i < mItems.size(); i++) {
1250
            ItemInfo ii = mItems.get(i);
1251
            if (ii.position == position) {
1252
                return ii;
1253
            }
1254
        }
1255
        return null;
1256
    }
1257
1258
    @Override
1259
    protected void onAttachedToWindow() {
1260
        super.onAttachedToWindow();
1261
        mFirstLayout = true;
1262
    }
1263
1264
    @Override
1265
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
1266
        // For simple implementation, our internal size is always 0.
1267
        // We depend on the container to specify the layout size of
1268
        // our view.  We can't really know what it is since we will be
1269
        // adding and removing different arbitrary views and do not
1270
        // want the layout to change as this happens.
1271
        setMeasuredDimension(getDefaultSize(0, widthMeasureSpec),
1272
                getDefaultSize(0, heightMeasureSpec));
1273
1274
        final int measuredHeight = getMeasuredHeight();
1275
        final int maxGutterSize = measuredHeight / 10;
1276
        mGutterSize = Math.min(maxGutterSize, mDefaultGutterSize);
1277
1278
        // Children are just made to fill our space.
1279
        int childWidthSize = getMeasuredWidth() - getPaddingLeft() - getPaddingRight();
1280
        int childHeightSize = measuredHeight - getPaddingTop() - getPaddingBottom();
1281
1282
        /*
1283
         * Make sure all children have been properly measured. Decor views first.
1284
         * Right now we cheat and make this less complicated by assuming decor
1285
         * views won't intersect. We will pin to edges based on gravity.
1286
         */
1287
        int size = getChildCount();
1288
        for (int i = 0; i < size; ++i) {
1289
            final View child = getChildAt(i);
1290
            if (child.getVisibility() != GONE) {
1291
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
1292
                if (lp != null && lp.isDecor) {
1293
                    final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
1294
                    final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
1295
                    int widthMode = MeasureSpec.AT_MOST;
1296
                    int heightMode = MeasureSpec.AT_MOST;
1297
                    boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM;
1298
                    boolean consumeHorizontal = hgrav == Gravity.LEFT || hgrav == Gravity.RIGHT;
1299
1300
                    if (consumeVertical) {
1301
                        widthMode = MeasureSpec.EXACTLY;
1302
                    } else if (consumeHorizontal) {
1303
                        heightMode = MeasureSpec.EXACTLY;
1304
                    }
1305
1306
                    int widthSize = childWidthSize;
1307
                    int heightSize = childHeightSize;
1308
                    if (lp.width != LayoutParams.WRAP_CONTENT) {
1309
                        widthMode = MeasureSpec.EXACTLY;
1310
                        if (lp.width != LayoutParams.FILL_PARENT) {
1311
                            widthSize = lp.width;
1312
                        }
1313
                    }
1314
                    if (lp.height != LayoutParams.WRAP_CONTENT) {
1315
                        heightMode = MeasureSpec.EXACTLY;
1316
                        if (lp.height != LayoutParams.FILL_PARENT) {
1317
                            heightSize = lp.height;
1318
                        }
1319
                    }
1320
                    final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
1321
                    final int heightSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
1322
                    child.measure(widthSpec, heightSpec);
1323
1324
                    if (consumeVertical) {
1325
                        childHeightSize -= child.getMeasuredHeight();
1326
                    } else if (consumeHorizontal) {
1327
                        childWidthSize -= child.getMeasuredWidth();
1328
                    }
1329
                }
1330
            }
1331
        }
1332
1333
        mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
1334
        mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY);
1335
1336
        // Make sure we have created all fragments that we need to have shown.
1337
        mInLayout = true;
1338
        populate();
1339
        mInLayout = false;
1340
1341
        // Page views next.
1342
        size = getChildCount();
1343
        for (int i = 0; i < size; ++i) {
1344
            final View child = getChildAt(i);
1345
            if (child.getVisibility() != GONE) {
1346
                if (DEBUG) Log.v(TAG, "Measuring #" + i + " " + child
1347
                        + ": " + mChildWidthMeasureSpec);
1348
1349
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
1350
                if (lp == null || !lp.isDecor) {
1351
                    final int heightSpec = MeasureSpec.makeMeasureSpec(
1352
                            (int) (childHeightSize * lp.heightFactor), MeasureSpec.EXACTLY);
1353
                    child.measure(mChildWidthMeasureSpec, heightSpec);
1354
                }
1355
            }
1356
        }
1357
    }
1358
1359
    @Override
1360
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
1361
        super.onSizeChanged(w, h, oldw, oldh);
1362
1363
        // Make sure scroll position is set correctly.
1364
        if (h != oldh) {
1365
            recomputeScrollPosition(h, oldh, mPageMargin, mPageMargin);
1366
        }
1367
    }
1368
1369
    private void recomputeScrollPosition(int height, int oldHeight, int margin, int oldMargin) {
1370
        if (oldHeight > 0 && !mItems.isEmpty()) {
1371
            final int heightWithMargin = height - getPaddingTop() - getPaddingBottom() + margin;
1372
            final int oldHeightWithMargin = oldHeight - getPaddingTop() - getPaddingBottom()
1373
                    + oldMargin;
1374
            final int ypos = getScrollY();
1375
            final float pageOffset = (float) ypos / oldHeightWithMargin;
1376
            final int newOffsetPixels = (int) (pageOffset * heightWithMargin);
1377
1378
            scrollTo(getScrollX(), newOffsetPixels);
1379
            if (!mScroller.isFinished()) {
1380
                // We now return to your regularly scheduled scroll, already in progress.
1381
                final int newDuration = mScroller.getDuration() - mScroller.timePassed();
1382
                ItemInfo targetInfo = infoForPosition(mCurItem);
1383
                mScroller.startScroll(0, newOffsetPixels,
1384
                        0, (int) (targetInfo.offset * height), newDuration);
1385
            }
1386
        } else {
1387
            final ItemInfo ii = infoForPosition(mCurItem);
1388
            final float scrollOffset = ii != null ? Math.min(ii.offset, mLastOffset) : 0;
1389
            final int scrollPos = (int) (scrollOffset *
1390
                    (height - getPaddingTop() - getPaddingBottom()));
1391
            if (scrollPos != getScrollY()) {
1392
                completeScroll(false);
1393
                scrollTo(getScrollX(), scrollPos);
1394
            }
1395
        }
1396
    }
1397
1398
    @Override
1399
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
1400
        final int count = getChildCount();
1401
        int width = r - l;
1402
        int height = b - t;
1403
        int paddingLeft = getPaddingLeft();
1404
        int paddingTop = getPaddingTop();
1405
        int paddingRight = getPaddingRight();
1406
        int paddingBottom = getPaddingBottom();
1407
        final int scrollY = getScrollY();
1408
1409
        int decorCount = 0;
1410
1411
        // First pass - decor views. We need to do this in two passes so that
1412
        // we have the proper offsets for non-decor views later.
1413
        for (int i = 0; i < count; i++) {
1414
            final View child = getChildAt(i);
1415
            if (child.getVisibility() != GONE) {
1416
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
1417
                int childLeft = 0;
1418
                int childTop = 0;
1419
                if (lp.isDecor) {
1420
                    final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
1421
                    final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
1422
                    switch (hgrav) {
1423
                        default:
1424
                            childLeft = paddingLeft;
1425
                            break;
1426
                        case Gravity.LEFT:
1427
                            childLeft = paddingLeft;
1428
                            paddingLeft += child.getMeasuredWidth();
1429
                            break;
1430
                        case Gravity.CENTER_HORIZONTAL:
1431
                            childLeft = Math.max((width - child.getMeasuredWidth()) / 2,
1432
                                    paddingLeft);
1433
                            break;
1434
                        case Gravity.RIGHT:
1435
                            childLeft = width - paddingRight - child.getMeasuredWidth();
1436
                            paddingRight += child.getMeasuredWidth();
1437
                            break;
1438
                    }
1439
                    switch (vgrav) {
1440
                        default:
1441
                            childTop = paddingTop;
1442
                            break;
1443
                        case Gravity.TOP:
1444
                            childTop = paddingTop;
1445
                            paddingTop += child.getMeasuredHeight();
1446
                            break;
1447
                        case Gravity.CENTER_VERTICAL:
1448
                            childTop = Math.max((height - child.getMeasuredHeight()) / 2,
1449
                                    paddingTop);
1450
                            break;
1451
                        case Gravity.BOTTOM:
1452
                            childTop = height - paddingBottom - child.getMeasuredHeight();
1453
                            paddingBottom += child.getMeasuredHeight();
1454
                            break;
1455
                    }
1456
                    childTop += scrollY;
1457
                    child.layout(childLeft, childTop,
1458
                            childLeft + child.getMeasuredWidth(),
1459
                            childTop + child.getMeasuredHeight());
1460
                    decorCount++;
1461
                }
1462
            }
1463
        }
1464
1465
        final int childHeight = height - paddingTop - paddingBottom;
1466
        // Page views. Do this once we have the right padding offsets from above.
1467
        for (int i = 0; i < count; i++) {
1468
            final View child = getChildAt(i);
1469
            if (child.getVisibility() != GONE) {
1470
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
1471
                ItemInfo ii;
1472
                if (!lp.isDecor && (ii = infoForChild(child)) != null) {
1473
                    int toff = (int) (childHeight * ii.offset);
1474
                    int childLeft = paddingLeft;
1475
                    int childTop = paddingTop + toff;
1476
                    if (lp.needsMeasure) {
1477
                        // This was added during layout and needs measurement.
1478
                        // Do it now that we know what we're working with.
1479
                        lp.needsMeasure = false;
1480
                        final int widthSpec = MeasureSpec.makeMeasureSpec(
1481
                                (int) (width - paddingLeft - paddingRight),
1482
                                MeasureSpec.EXACTLY);
1483
                        final int heightSpec = MeasureSpec.makeMeasureSpec(
1484
                                (int) (childHeight * lp.heightFactor),
1485
                                MeasureSpec.EXACTLY);
1486
                        child.measure(widthSpec, heightSpec);
1487
                    }
1488
                    if (DEBUG) Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object
1489
                            + ":" + childLeft + "," + childTop + " " + child.getMeasuredWidth()
1490
                            + "x" + child.getMeasuredHeight());
1491
                    child.layout(childLeft, childTop,
1492
                            childLeft + child.getMeasuredWidth(),
1493
                            childTop + child.getMeasuredHeight());
1494
                }
1495
            }
1496
        }
1497
        mLeftPageBounds = paddingLeft;
1498
        mRightPageBounds = width - paddingRight;
1499
        mDecorChildCount = decorCount;
1500
1501
        if (mFirstLayout) {
1502
            scrollToItem(mCurItem, false, 0, false);
1503
        }
1504
        mFirstLayout = false;
1505
    }
1506
1507
    @Override
1508
    public void computeScroll() {
1509
        if (!mScroller.isFinished() && mScroller.computeScrollOffset()) {
1510
            int oldX = getScrollX();
1511
            int oldY = getScrollY();
1512
            int x = mScroller.getCurrX();
1513
            int y = mScroller.getCurrY();
1514
1515
            if (oldX != x || oldY != y) {
1516
                scrollTo(x, y);
1517
                if (!pageScrolled(y)) {
1518
                    mScroller.abortAnimation();
1519
                    scrollTo(x, 0);
1520
                }
1521
            }
1522
1523
            // Keep on drawing until the animation has finished.
1524
            ViewCompat.postInvalidateOnAnimation(this);
1525
            return;
1526
        }
1527
1528
        // Done with scroll, clean up state.
1529
        completeScroll(true);
1530
    }
1531
1532
    private boolean pageScrolled(int ypos) {
1533
        if (mItems.size() == 0) {
1534
            mCalledSuper = false;
1535
            onPageScrolled(0, 0, 0);
1536
            if (!mCalledSuper) {
1537
                throw new IllegalStateException(
1538
                        "onPageScrolled did not call superclass implementation");
1539
            }
1540
            return false;
1541
        }
1542
        final ItemInfo ii = infoForCurrentScrollPosition();
1543
        final int height = getClientHeight();
1544
        final int heightWithMargin = height + mPageMargin;
1545
        final float marginOffset = (float) mPageMargin / height;
1546
        final int currentPage = ii.position;
1547
        final float pageOffset = (((float) ypos / height) - ii.offset) /
1548
                (ii.heightFactor + marginOffset);
1549
        final int offsetPixels = (int) (pageOffset * heightWithMargin);
1550
1551
        mCalledSuper = false;
1552
        onPageScrolled(currentPage, pageOffset, offsetPixels);
1553
        if (!mCalledSuper) {
1554
            throw new IllegalStateException(
1555
                    "onPageScrolled did not call superclass implementation");
1556
        }
1557
        return true;
1558
    }
1559
1560
    /**
1561
     * This method will be invoked when the current page is scrolled, either as part
1562
     * of a programmatically initiated smooth scroll or a user initiated touch scroll.
1563
     * If you override this method you must call through to the superclass implementation
1564
     * (e.g. super.onPageScrolled(position, offset, offsetPixels)) before onPageScrolled
1565
     * returns.
1566
     *
1567
     * @param position     Position index of the first page currently being displayed.
1568
     *                     Page position+1 will be visible if positionOffset is nonzero.
1569
     * @param offset       Value from [0, 1) indicating the offset from the page at position.
1570
     * @param offsetPixels Value in pixels indicating the offset from position.
1571
     */
1572
    protected void onPageScrolled(int position, float offset, int offsetPixels) {
1573
        // Offset any decor views if needed - keep them on-screen at all times.
1574
        if (mDecorChildCount > 0) {
1575
            final int scrollY = getScrollY();
1576
            int paddingTop = getPaddingTop();
1577
            int paddingBottom = getPaddingBottom();
1578
            final int height = getHeight();
1579
            final int childCount = getChildCount();
1580
            for (int i = 0; i < childCount; i++) {
1581
                final View child = getChildAt(i);
1582
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
1583
                if (!lp.isDecor) continue;
1584
1585
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
1586
                int childTop = 0;
1587
                switch (vgrav) {
1588
                    default:
1589
                        childTop = paddingTop;
1590
                        break;
1591
                    case Gravity.TOP:
1592
                        childTop = paddingTop;
1593
                        paddingTop += child.getHeight();
1594
                        break;
1595
                    case Gravity.CENTER_VERTICAL:
1596
                        childTop = Math.max((height - child.getMeasuredHeight()) / 2,
1597
                                paddingTop);
1598
                        break;
1599
                    case Gravity.BOTTOM:
1600
                        childTop = height - paddingBottom - child.getMeasuredHeight();
1601
                        paddingBottom += child.getMeasuredHeight();
1602
                        break;
1603
                }
1604
                childTop += scrollY;
1605
1606
                final int childOffset = childTop - child.getTop();
1607
                if (childOffset != 0) {
1608
                    child.offsetTopAndBottom(childOffset);
1609
                }
1610
            }
1611
        }
1612
1613
        if (mOnPageChangeListener != null) {
1614
            mOnPageChangeListener.onPageScrolled(position, offset, offsetPixels);
1615
        }
1616
        if (mInternalPageChangeListener != null) {
1617
            mInternalPageChangeListener.onPageScrolled(position, offset, offsetPixels);
1618
        }
1619
1620
        if (mPageTransformer != null) {
1621
            final int scrollY = getScrollY();
1622
            final int childCount = getChildCount();
1623
            for (int i = 0; i < childCount; i++) {
1624
                final View child = getChildAt(i);
1625
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
1626
1627
                if (lp.isDecor) continue;
1628
1629
                final float transformPos = (float) (child.getTop() - scrollY) / getClientHeight();
1630
                mPageTransformer.transformPage(child, transformPos);
1631
            }
1632
        }
1633
1634
        mCalledSuper = true;
1635
    }
1636
1637
    private void completeScroll(boolean postEvents) {
1638
        boolean needPopulate = mScrollState == SCROLL_STATE_SETTLING;
1639
        if (needPopulate) {
1640
            // Done with scroll, no longer want to cache view drawing.
1641
            setScrollingCacheEnabled(false);
1642
            mScroller.abortAnimation();
1643
            int oldX = getScrollX();
1644
            int oldY = getScrollY();
1645
            int x = mScroller.getCurrX();
1646
            int y = mScroller.getCurrY();
1647
            if (oldX != x || oldY != y) {
1648
                scrollTo(x, y);
1649
            }
1650
        }
1651
        mPopulatePending = false;
1652
        for (int i = 0; i < mItems.size(); i++) {
1653
            ItemInfo ii = mItems.get(i);
1654
            if (ii.scrolling) {
1655
                needPopulate = true;
1656
                ii.scrolling = false;
1657
            }
1658
        }
1659
        if (needPopulate) {
1660
            if (postEvents) {
1661
                ViewCompat.postOnAnimation(this, mEndScrollRunnable);
1662
            } else {
1663
                mEndScrollRunnable.run();
1664
            }
1665
        }
1666
    }
1667
1668
    private boolean isGutterDrag(float y, float dy) {
1669
        return (y < mGutterSize && dy > 0) || (y > getHeight() - mGutterSize && dy < 0);
1670
    }
1671
1672
    private void enableLayers(boolean enable) {
1673
        final int childCount = getChildCount();
1674
        for (int i = 0; i < childCount; i++) {
1675
            final int layerType = enable ?
1676
                    ViewCompat.LAYER_TYPE_HARDWARE : ViewCompat.LAYER_TYPE_NONE;
1677
            ViewCompat.setLayerType(getChildAt(i), layerType, null);
1678
        }
1679
    }
1680
1681
    @Override
1682
    public boolean onInterceptTouchEvent(MotionEvent ev) {
1683
        /*
1684
         * This method JUST determines whether we want to intercept the motion.
1685
         * If we return true, onMotionEvent will be called and we do the actual
1686
         * scrolling there.
1687
         */
1688
1689
        final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
1690
1691
        // Always take care of the touch gesture being complete.
1692
        if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
1693
            // Release the drag.
1694
            if (DEBUG) Log.v(TAG, "Intercept done!");
1695
            mIsBeingDragged = false;
1696
            mIsUnableToDrag = false;
1697
            mActivePointerId = INVALID_POINTER;
1698
            if (mVelocityTracker != null) {
1699
                mVelocityTracker.recycle();
1700
                mVelocityTracker = null;
1701
            }
1702
            return false;
1703
        }
1704
1705
        // Nothing more to do here if we have decided whether or not we
1706
        // are dragging.
1707
        if (action != MotionEvent.ACTION_DOWN) {
1708
            if (mIsBeingDragged) {
1709
                if (DEBUG) Log.v(TAG, "Intercept returning true!");
1710
                return true;
1711
            }
1712
            if (mIsUnableToDrag) {
1713
                if (DEBUG) Log.v(TAG, "Intercept returning false!");
1714
                return false;
1715
            }
1716
        }
1717
1718
        switch (action) {
1719
            case MotionEvent.ACTION_MOVE: {
1720
                /*
1721
                 * mIsBeingDragged == false, otherwise the shortcut would have caught it. Check
1722
                 * whether the user has moved far enough from his original down touch.
1723
                 */
1724
1725
                /*
1726
                 * Locally do absolute value. mLastMotionY is set to the y value
1727
                 * of the down event.
1728
                 */
1729
                final int activePointerId = mActivePointerId;
1730
                if (activePointerId == INVALID_POINTER) {
1731
                    // If we don't have a valid id, the touch down wasn't on content.
1732
                    break;
1733
                }
1734
1735
                final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
1736
                final float y = MotionEventCompat.getY(ev, pointerIndex);
1737
                final float dy = y - mLastMotionY;
1738
                final float yDiff = Math.abs(dy);
1739
                final float x = MotionEventCompat.getX(ev, pointerIndex);
1740
                final float xDiff = Math.abs(x - mInitialMotionX);
1741
                if (DEBUG) Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
1742
1743
                if (dy != 0 && !isGutterDrag(mLastMotionY, dy) &&
1744
                        canScroll(this, false, (int) dy, (int) x, (int) y)) {
1745
                    // Nested view has scrollable area under this point. Let it be handled there.
1746
                    mLastMotionX = x;
1747
                    mLastMotionY = y;
1748
                    mIsUnableToDrag = true;
1749
                    return false;
1750
                }
1751
                if (yDiff > mTouchSlop && yDiff * 0.5f > xDiff) {
1752
                    if (DEBUG) Log.v(TAG, "Starting drag!");
1753
                    mIsBeingDragged = true;
1754
                    requestParentDisallowInterceptTouchEvent(true);
1755
                    setScrollState(SCROLL_STATE_DRAGGING);
1756
                    mLastMotionY = dy > 0 ? mInitialMotionY + mTouchSlop :
1757
                            mInitialMotionY - mTouchSlop;
1758
                    mLastMotionX = x;
1759
                    setScrollingCacheEnabled(true);
1760
                } else if (xDiff > mTouchSlop) {
1761
                    // The finger has moved enough in the vertical
1762
                    // direction to be counted as a drag...  abort
1763
                    // any attempt to drag horizontally, to work correctly
1764
                    // with children that have scrolling containers.
1765
                    if (DEBUG) Log.v(TAG, "Starting unable to drag!");
1766
                    mIsUnableToDrag = true;
1767
                }
1768
                if (mIsBeingDragged) {
1769
                    // Scroll to follow the motion event
1770
                    if (performDrag(y)) {
1771
                        ViewCompat.postInvalidateOnAnimation(this);
1772
                    }
1773
                }
1774
                break;
1775
            }
1776
1777
            case MotionEvent.ACTION_DOWN: {
1778
                /*
1779
                 * Remember location of down touch.
1780
                 * ACTION_DOWN always refers to pointer index 0.
1781
                 */
1782
                mLastMotionX = mInitialMotionX = ev.getX();
1783
                mLastMotionY = mInitialMotionY = ev.getY();
1784
                mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
1785
                mIsUnableToDrag = false;
1786
1787
                mScroller.computeScrollOffset();
1788
                if (mScrollState == SCROLL_STATE_SETTLING &&
1789
                        Math.abs(mScroller.getFinalY() - mScroller.getCurrY()) > mCloseEnough) {
1790
                    // Let the user 'catch' the pager as it animates.
1791
                    mScroller.abortAnimation();
1792
                    mPopulatePending = false;
1793
                    populate();
1794
                    mIsBeingDragged = true;
1795
                    requestParentDisallowInterceptTouchEvent(true);
1796
                    setScrollState(SCROLL_STATE_DRAGGING);
1797
                } else {
1798
                    completeScroll(false);
1799
                    mIsBeingDragged = false;
1800
                }
1801
1802
                if (DEBUG) Log.v(TAG, "Down at " + mLastMotionX + "," + mLastMotionY
1803
                        + " mIsBeingDragged=" + mIsBeingDragged
1804
                        + "mIsUnableToDrag=" + mIsUnableToDrag);
1805
                break;
1806
            }
1807
1808
            case MotionEventCompat.ACTION_POINTER_UP:
1809
                onSecondaryPointerUp(ev);
1810
                break;
1811
        }
1812
1813
        if (mVelocityTracker == null) {
1814
            mVelocityTracker = VelocityTracker.obtain();
1815
        }
1816
        mVelocityTracker.addMovement(ev);
1817
1818
        /*
1819
         * The only time we want to intercept motion events is if we are in the
1820
         * drag mode.
1821
         */
1822
        return mIsBeingDragged;
1823
    }
1824
1825
    @Override
1826
    public boolean onTouchEvent(MotionEvent ev) {
1827
        if (mFakeDragging) {
1828
            // A fake drag is in progress already, ignore this real one
1829
            // but still eat the touch events.
1830
            // (It is likely that the user is multi-touching the screen.)
1831
            return true;
1832
        }
1833
1834
        if (ev.getAction() == MotionEvent.ACTION_DOWN && ev.getEdgeFlags() != 0) {
1835
            // Don't handle edge touches immediately -- they may actually belong to one of our
1836
            // descendants.
1837
            return false;
1838
        }
1839
1840
        if (mAdapter == null || mAdapter.getCount() == 0) {
1841
            // Nothing to present or scroll; nothing to touch.
1842
            return false;
1843
        }
1844
1845
        if (mVelocityTracker == null) {
1846
            mVelocityTracker = VelocityTracker.obtain();
1847
        }
1848
        mVelocityTracker.addMovement(ev);
1849
1850
        final int action = ev.getAction();
1851
        boolean needsInvalidate = false;
1852
1853
        switch (action & MotionEventCompat.ACTION_MASK) {
1854
            case MotionEvent.ACTION_DOWN: {
1855
                mScroller.abortAnimation();
1856
                mPopulatePending = false;
1857
                populate();
1858
1859
                // Remember where the motion event started
1860
                mLastMotionX = mInitialMotionX = ev.getX();
1861
                mLastMotionY = mInitialMotionY = ev.getY();
1862
                mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
1863
                break;
1864
            }
1865
            case MotionEvent.ACTION_MOVE:
1866
                if (!mIsBeingDragged) {
1867
                    final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
1868
                    final float y = MotionEventCompat.getY(ev, pointerIndex);
1869
                    final float yDiff = Math.abs(y - mLastMotionY);
1870
                    final float x = MotionEventCompat.getX(ev, pointerIndex);
1871
                    final float xDiff = Math.abs(x - mLastMotionX);
1872
                    if (DEBUG)
1873
                        Log.v(TAG, "Moved x to " + x + "," + y + " diff=" + xDiff + "," + yDiff);
1874
                    if (yDiff > mTouchSlop && yDiff > xDiff) {
1875
                        if (DEBUG) Log.v(TAG, "Starting drag!");
1876
                        mIsBeingDragged = true;
1877
                        requestParentDisallowInterceptTouchEvent(true);
1878
                        mLastMotionY = y - mInitialMotionY > 0 ? mInitialMotionY + mTouchSlop :
1879
                                mInitialMotionY - mTouchSlop;
1880
                        mLastMotionX = x;
1881
                        setScrollState(SCROLL_STATE_DRAGGING);
1882
                        setScrollingCacheEnabled(true);
1883
1884
                        // Disallow Parent Intercept, just in case
1885
                        ViewParent parent = getParent();
1886
                        if (parent != null) {
1887
                            parent.requestDisallowInterceptTouchEvent(true);
1888
                        }
1889
                    }
1890
                }
1891
                // Not else! Note that mIsBeingDragged can be set above.
1892
                if (mIsBeingDragged) {
1893
                    // Scroll to follow the motion event
1894
                    final int activePointerIndex = MotionEventCompat.findPointerIndex(
1895
                            ev, mActivePointerId);
1896
                    final float y = MotionEventCompat.getY(ev, activePointerIndex);
1897
                    needsInvalidate |= performDrag(y);
1898
                }
1899
                break;
1900
            case MotionEvent.ACTION_UP:
1901
                if (mIsBeingDragged) {
1902
                    final VelocityTracker velocityTracker = mVelocityTracker;
1903
                    velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
1904
                    int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(
1905
                            velocityTracker, mActivePointerId);
1906
                    mPopulatePending = true;
1907
                    final int height = getClientHeight();
1908
                    final int scrollY = getScrollY();
1909
                    final ItemInfo ii = infoForCurrentScrollPosition();
1910
                    final int currentPage = ii.position;
1911
                    final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor;
1912
                    final int activePointerIndex =
1913
                            MotionEventCompat.findPointerIndex(ev, mActivePointerId);
1914
                    final float y = MotionEventCompat.getY(ev, activePointerIndex);
1915
                    final int totalDelta = (int) (y - mInitialMotionY);
1916
                    int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
1917
                            totalDelta);
1918
                    setCurrentItemInternal(nextPage, true, true, initialVelocity);
1919
1920
                    mActivePointerId = INVALID_POINTER;
1921
                    endDrag();
1922
                    needsInvalidate = mTopEdge.onRelease() | mBottomEdge.onRelease();
1923
                }
1924
                break;
1925
            case MotionEvent.ACTION_CANCEL:
1926
                if (mIsBeingDragged) {
1927
                    scrollToItem(mCurItem, true, 0, false);
1928
                    mActivePointerId = INVALID_POINTER;
1929
                    endDrag();
1930
                    needsInvalidate = mTopEdge.onRelease() | mBottomEdge.onRelease();
1931
                }
1932
                break;
1933
            case MotionEventCompat.ACTION_POINTER_DOWN: {
1934
                final int index = MotionEventCompat.getActionIndex(ev);
1935
                final float y = MotionEventCompat.getY(ev, index);
1936
                mLastMotionY = y;
1937
                mActivePointerId = MotionEventCompat.getPointerId(ev, index);
1938
                break;
1939
            }
1940
            case MotionEventCompat.ACTION_POINTER_UP:
1941
                onSecondaryPointerUp(ev);
1942
                mLastMotionY = MotionEventCompat.getY(ev,
1943
                        MotionEventCompat.findPointerIndex(ev, mActivePointerId));
1944
                break;
1945
        }
1946
        if (needsInvalidate) {
1947
            ViewCompat.postInvalidateOnAnimation(this);
1948
        }
1949
        return true;
1950
    }
1951
1952
    private void requestParentDisallowInterceptTouchEvent(boolean disallowIntercept) {
1953
        final ViewParent parent = getParent();
1954
        if (parent != null) {
1955
            parent.requestDisallowInterceptTouchEvent(disallowIntercept);
1956
        }
1957
    }
1958
1959
    private boolean performDrag(float y) {
1960
        boolean needsInvalidate = false;
1961
1962
        final float deltaY = mLastMotionY - y;
1963
        mLastMotionY = y;
1964
1965
        float oldScrollY = getScrollY();
1966
        float scrollY = oldScrollY + deltaY;
1967
        final int height = getClientHeight();
1968
1969
        float topBound = height * mFirstOffset;
1970
        float bottomBound = height * mLastOffset;
1971
        boolean topAbsolute = true;
1972
        boolean bottomAbsolute = true;
1973
1974
        final ItemInfo firstItem = mItems.get(0);
1975
        final ItemInfo lastItem = mItems.get(mItems.size() - 1);
1976
        if (firstItem.position != 0) {
1977
            topAbsolute = false;
1978
            topBound = firstItem.offset * height;
1979
        }
1980
        if (lastItem.position != mAdapter.getCount() - 1) {
1981
            bottomAbsolute = false;
1982
            bottomBound = lastItem.offset * height;
1983
        }
1984
1985
        if (scrollY < topBound) {
1986
            if (topAbsolute) {
1987
                float over = topBound - scrollY;
1988
                needsInvalidate = mTopEdge.onPull(Math.abs(over) / height);
1989
            }
1990
            scrollY = topBound;
1991
        } else if (scrollY > bottomBound) {
1992
            if (bottomAbsolute) {
1993
                float over = scrollY - bottomBound;
1994
                needsInvalidate = mBottomEdge.onPull(Math.abs(over) / height);
1995
            }
1996
            scrollY = bottomBound;
1997
        }
1998
        // Don't lose the rounded component
1999
        mLastMotionX += scrollY - (int) scrollY;
2000
        scrollTo(getScrollX(), (int) scrollY);
2001
        pageScrolled((int) scrollY);
2002
2003
        return needsInvalidate;
2004
    }
2005
2006
    /**
2007
     * @return Info about the page at the current scroll position.
2008
     * This can be synthetic for a missing middle page; the 'object' field can be null.
2009
     */
2010
    private ItemInfo infoForCurrentScrollPosition() {
2011
        final int height = getClientHeight();
2012
        final float scrollOffset = height > 0 ? (float) getScrollY() / height : 0;
2013
        final float marginOffset = height > 0 ? (float) mPageMargin / height : 0;
2014
        int lastPos = -1;
2015
        float lastOffset = 0.f;
2016
        float lastHeight = 0.f;
2017
        boolean first = true;
2018
2019
        ItemInfo lastItem = null;
2020
        for (int i = 0; i < mItems.size(); i++) {
2021
            ItemInfo ii = mItems.get(i);
2022
            float offset;
2023
            if (!first && ii.position != lastPos + 1) {
2024
                // Create a synthetic item for a missing page.
2025
                ii = mTempItem;
2026
                ii.offset = lastOffset + lastHeight + marginOffset;
2027
                ii.position = lastPos + 1;
2028
                ii.heightFactor = mAdapter.getPageWidth(ii.position);
2029
                i--;
2030
            }
2031
            offset = ii.offset;
2032
2033
            final float topBound = offset;
2034
            final float bottomBound = offset + ii.heightFactor + marginOffset;
2035
            if (first || scrollOffset >= topBound) {
2036
                if (scrollOffset < bottomBound || i == mItems.size() - 1) {
2037
                    return ii;
2038
                }
2039
            } else {
2040
                return lastItem;
2041
            }
2042
            first = false;
2043
            lastPos = ii.position;
2044
            lastOffset = offset;
2045
            lastHeight = ii.heightFactor;
2046
            lastItem = ii;
2047
        }
2048
2049
        return lastItem;
2050
    }
2051
2052
    private int determineTargetPage(int currentPage, float pageOffset, int velocity, int deltaY) {
2053
        int targetPage;
2054
        if (Math.abs(deltaY) > mFlingDistance && Math.abs(velocity) > mMinimumVelocity) {
2055
            targetPage = velocity > 0 ? currentPage : currentPage + 1;
2056
        } else {
2057
            final float truncator = currentPage >= mCurItem ? 0.4f : 0.6f;
2058
            targetPage = (int) (currentPage + pageOffset + truncator);
2059
        }
2060
2061
        if (mItems.size() > 0) {
2062
            final ItemInfo firstItem = mItems.get(0);
2063
            final ItemInfo lastItem = mItems.get(mItems.size() - 1);
2064
2065
            // Only let the user target pages we have items for
2066
            targetPage = Math.max(firstItem.position, Math.min(targetPage, lastItem.position));
2067
        }
2068
2069
        return targetPage;
2070
    }
2071
2072
    @Override
2073
    public void draw(Canvas canvas) {
2074
        super.draw(canvas);
2075
        boolean needsInvalidate = false;
2076
2077
        final int overScrollMode = ViewCompat.getOverScrollMode(this);
2078
        if (overScrollMode == ViewCompat.OVER_SCROLL_ALWAYS ||
2079
                (overScrollMode == ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS &&
2080
                        mAdapter != null && mAdapter.getCount() > 1)) {
2081
            if (!mTopEdge.isFinished()) {
2082
                final int restoreCount = canvas.save();
2083
                final int height = getHeight();
2084
                final int width = getWidth() - getPaddingLeft() - getPaddingRight();
2085
2086
                canvas.translate(getPaddingLeft(), mFirstOffset * height);
2087
                mTopEdge.setSize(width, height);
2088
                needsInvalidate |= mTopEdge.draw(canvas);
2089
                canvas.restoreToCount(restoreCount);
2090
            }
2091
            if (!mBottomEdge.isFinished()) {
2092
                final int restoreCount = canvas.save();
2093
                final int height = getHeight();
2094
                final int width = getWidth() - getPaddingLeft() - getPaddingRight();
2095
2096
                canvas.rotate(180);
2097
                canvas.translate(-width - getPaddingLeft(), -(mLastOffset + 1) * height);
2098
                mBottomEdge.setSize(width, height);
2099
                needsInvalidate |= mBottomEdge.draw(canvas);
2100
                canvas.restoreToCount(restoreCount);
2101
            }
2102
        } else {
2103
            mTopEdge.finish();
2104
            mBottomEdge.finish();
2105
        }
2106
2107
        if (needsInvalidate) {
2108
            // Keep animating
2109
            ViewCompat.postInvalidateOnAnimation(this);
2110
        }
2111
    }
2112
2113
    @Override
2114
    protected void onDraw(Canvas canvas) {
2115
        super.onDraw(canvas);
2116
2117
        // Draw the margin drawable between pages if needed.
2118
        if (mPageMargin > 0 && mMarginDrawable != null && mItems.size() > 0 && mAdapter != null) {
2119
            final int scrollY = getScrollY();
2120
            final int height = getHeight();
2121
2122
            final float marginOffset = (float) mPageMargin / height;
2123
            int itemIndex = 0;
2124
            ItemInfo ii = mItems.get(0);
2125
            float offset = ii.offset;
2126
            final int itemCount = mItems.size();
2127
            final int firstPos = ii.position;
2128
            final int lastPos = mItems.get(itemCount - 1).position;
2129
            for (int pos = firstPos; pos < lastPos; pos++) {
2130
                while (pos > ii.position && itemIndex < itemCount) {
2131
                    ii = mItems.get(++itemIndex);
2132
                }
2133
2134
                float drawAt;
2135
                if (pos == ii.position) {
2136
                    drawAt = (ii.offset + ii.heightFactor) * height;
2137
                    offset = ii.offset + ii.heightFactor + marginOffset;
2138
                } else {
2139
                    float heightFactor = mAdapter.getPageWidth(pos);
2140
                    drawAt = (offset + heightFactor) * height;
2141
                    offset += heightFactor + marginOffset;
2142
                }
2143
2144
                if (drawAt + mPageMargin > scrollY) {
2145
                    mMarginDrawable.setBounds(mLeftPageBounds, (int) drawAt,
2146
                            mRightPageBounds, (int) (drawAt + mPageMargin + 0.5f));
2147
                    mMarginDrawable.draw(canvas);
2148
                }
2149
2150
                if (drawAt > scrollY + height) {
2151
                    break; // No more visible, no sense in continuing
2152
                }
2153
            }
2154
        }
2155
    }
2156
2157
    /**
2158
     * Start a fake drag of the pager.
2159
     * <p/>
2160
     * <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
2161
     * with the touch scrolling of another view, while still letting the ViewPager
2162
     * control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
2163
     * Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
2164
     * {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
2165
     * <p/>
2166
     * <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
2167
     * is already in progress, this method will return false.
2168
     *
2169
     * @return true if the fake drag began successfully, false if it could not be started.
2170
     * @see #fakeDragBy(float)
2171
     * @see #endFakeDrag()
2172
     */
2173
    public boolean beginFakeDrag() {
2174
        if (mIsBeingDragged) {
2175
            return false;
2176
        }
2177
        mFakeDragging = true;
2178
        setScrollState(SCROLL_STATE_DRAGGING);
2179
        mInitialMotionY = mLastMotionY = 0;
2180
        if (mVelocityTracker == null) {
2181
            mVelocityTracker = VelocityTracker.obtain();
2182
        } else {
2183
            mVelocityTracker.clear();
2184
        }
2185
        final long time = SystemClock.uptimeMillis();
2186
        final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
2187
        mVelocityTracker.addMovement(ev);
2188
        ev.recycle();
2189
        mFakeDragBeginTime = time;
2190
        return true;
2191
    }
2192
2193
    /**
2194
     * End a fake drag of the pager.
2195
     *
2196
     * @see #beginFakeDrag()
2197
     * @see #fakeDragBy(float)
2198
     */
2199
    public void endFakeDrag() {
2200
        if (!mFakeDragging) {
2201
            throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
2202
        }
2203
2204
        final VelocityTracker velocityTracker = mVelocityTracker;
2205
        velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
2206
        int initialVelocity = (int) VelocityTrackerCompat.getYVelocity(
2207
                velocityTracker, mActivePointerId);
2208
        mPopulatePending = true;
2209
        final int height = getClientHeight();
2210
        final int scrollY = getScrollY();
2211
        final ItemInfo ii = infoForCurrentScrollPosition();
2212
        final int currentPage = ii.position;
2213
        final float pageOffset = (((float) scrollY / height) - ii.offset) / ii.heightFactor;
2214
        final int totalDelta = (int) (mLastMotionY - mInitialMotionY);
2215
        int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity,
2216
                totalDelta);
2217
        setCurrentItemInternal(nextPage, true, true, initialVelocity);
2218
        endDrag();
2219
2220
        mFakeDragging = false;
2221
    }
2222
2223
    /**
2224
     * Fake drag by an offset in pixels. You must have called {@link #beginFakeDrag()} first.
2225
     *
2226
     * @param yOffset Offset in pixels to drag by.
2227
     * @see #beginFakeDrag()
2228
     * @see #endFakeDrag()
2229
     */
2230
    public void fakeDragBy(float yOffset) {
2231
        if (!mFakeDragging) {
2232
            throw new IllegalStateException("No fake drag in progress. Call beginFakeDrag first.");
2233
        }
2234
2235
        mLastMotionY += yOffset;
2236
2237
        float oldScrollY = getScrollY();
2238
        float scrollY = oldScrollY - yOffset;
2239
        final int height = getClientHeight();
2240
2241
        float topBound = height * mFirstOffset;
2242
        float bottomBound = height * mLastOffset;
2243
2244
        final ItemInfo firstItem = mItems.get(0);
2245
        final ItemInfo lastItem = mItems.get(mItems.size() - 1);
2246
        if (firstItem.position != 0) {
2247
            topBound = firstItem.offset * height;
2248
        }
2249
        if (lastItem.position != mAdapter.getCount() - 1) {
2250
            bottomBound = lastItem.offset * height;
2251
        }
2252
2253
        if (scrollY < topBound) {
2254
            scrollY = topBound;
2255
        } else if (scrollY > bottomBound) {
2256
            scrollY = bottomBound;
2257
        }
2258
        // Don't lose the rounded component
2259
        mLastMotionY += scrollY - (int) scrollY;
2260
        scrollTo(getScrollX(), (int) scrollY);
2261
        pageScrolled((int) scrollY);
2262
2263
        // Synthesize an event for the VelocityTracker.
2264
        final long time = SystemClock.uptimeMillis();
2265
        final MotionEvent ev = MotionEvent.obtain(mFakeDragBeginTime, time, MotionEvent.ACTION_MOVE,
2266
                0, mLastMotionY, 0);
2267
        mVelocityTracker.addMovement(ev);
2268
        ev.recycle();
2269
    }
2270
2271
    /**
2272
     * Returns true if a fake drag is in progress.
2273
     *
2274
     * @return true if currently in a fake drag, false otherwise.
2275
     * @see #beginFakeDrag()
2276
     * @see #fakeDragBy(float)
2277
     * @see #endFakeDrag()
2278
     */
2279
    public boolean isFakeDragging() {
2280
        return mFakeDragging;
2281
    }
2282
2283
    private void onSecondaryPointerUp(MotionEvent ev) {
2284
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
2285
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
2286
        if (pointerId == mActivePointerId) {
2287
            // This was our active pointer going up. Choose a new
2288
            // active pointer and adjust accordingly.
2289
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
2290
            mLastMotionY = MotionEventCompat.getY(ev, newPointerIndex);
2291
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
2292
            if (mVelocityTracker != null) {
2293
                mVelocityTracker.clear();
2294
            }
2295
        }
2296
    }
2297
2298
    private void endDrag() {
2299
        mIsBeingDragged = false;
2300
        mIsUnableToDrag = false;
2301
2302
        if (mVelocityTracker != null) {
2303
            mVelocityTracker.recycle();
2304
            mVelocityTracker = null;
2305
        }
2306
    }
2307
2308
    private void setScrollingCacheEnabled(boolean enabled) {
2309
        if (mScrollingCacheEnabled != enabled) {
2310
            mScrollingCacheEnabled = enabled;
2311
            if (USE_CACHE) {
2312
                final int size = getChildCount();
2313
                for (int i = 0; i < size; ++i) {
2314
                    final View child = getChildAt(i);
2315
                    if (child.getVisibility() != GONE) {
2316
                        child.setDrawingCacheEnabled(enabled);
2317
                    }
2318
                }
2319
            }
2320
        }
2321
    }
2322
2323
    public boolean internalCanScrollVertically(int direction) {
2324
        if (mAdapter == null) {
2325
            return false;
2326
        }
2327
2328
        final int height = getClientHeight();
2329
        final int scrollY = getScrollY();
2330
        if (direction < 0) {
2331
            return (scrollY > (int) (height * mFirstOffset));
2332
        } else if (direction > 0) {
2333
            return (scrollY < (int) (height * mLastOffset));
2334
        } else {
2335
            return false;
2336
        }
2337
    }
2338
2339
    /**
2340
     * Tests scrollability within child views of v given a delta of dx.
2341
     *
2342
     * @param v      View to test for horizontal scrollability
2343
     * @param checkV Whether the view v passed should itself be checked for scrollability (true),
2344
     *               or just its children (false).
2345
     * @param dy     Delta scrolled in pixels
2346
     * @param x      X coordinate of the active touch point
2347
     * @param y      Y coordinate of the active touch point
2348
     * @return true if child views of v can be scrolled by delta of dx.
2349
     */
2350
    protected boolean canScroll(View v, boolean checkV, int dy, int x, int y) {
2351
        if (v instanceof ViewGroup) {
2352
            final ViewGroup group = (ViewGroup) v;
2353
            final int scrollX = v.getScrollX();
2354
            final int scrollY = v.getScrollY();
2355
            final int count = group.getChildCount();
2356
            // Count backwards - let topmost views consume scroll distance first.
2357
            for (int i = count - 1; i >= 0; i--) {
2358
                // TODO: Add versioned support here for transformed views.
2359
                // This will not work for transformed views in Honeycomb+
2360
                final View child = group.getChildAt(i);
2361
                if (y + scrollY >= child.getTop() && y + scrollY < child.getBottom() &&
2362
                        x + scrollX >= child.getLeft() && x + scrollX < child.getRight() &&
2363
                        canScroll(child, true, dy, x + scrollX - child.getLeft(),
2364
                                y + scrollY - child.getTop())) {
2365
                    return true;
2366
                }
2367
            }
2368
        }
2369
2370
        return checkV && ViewCompat.canScrollVertically(v, -dy);
2371
    }
2372
2373
    @Override
2374
    public boolean dispatchKeyEvent(KeyEvent event) {
2375
        // Let the focused view and/or our descendants get the key first
2376
        return super.dispatchKeyEvent(event) || executeKeyEvent(event);
2377
    }
2378
2379
    /**
2380
     * You can call this function yourself to have the scroll view perform
2381
     * scrolling from a key event, just as if the event had been dispatched to
2382
     * it by the view hierarchy.
2383
     *
2384
     * @param event The key event to execute.
2385
     * @return Return true if the event was handled, else false.
2386
     */
2387
    public boolean executeKeyEvent(KeyEvent event) {
2388
        boolean handled = false;
2389
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
2390
            switch (event.getKeyCode()) {
2391
                case KeyEvent.KEYCODE_DPAD_LEFT:
2392
                    handled = arrowScroll(FOCUS_LEFT);
2393
                    break;
2394
                case KeyEvent.KEYCODE_DPAD_RIGHT:
2395
                    handled = arrowScroll(FOCUS_RIGHT);
2396
                    break;
2397
                case KeyEvent.KEYCODE_TAB:
2398
                    if (Build.VERSION.SDK_INT >= 11) {
2399
                        if (event.hasNoModifiers()) {
2400
                            handled = arrowScroll(FOCUS_FORWARD);
2401
                        } else if (event.hasModifiers(KeyEvent.META_SHIFT_ON)) {
2402
                            handled = arrowScroll(FOCUS_BACKWARD);
2403
                        }
2404
                    }
2405
                    break;
2406
            }
2407
        }
2408
        return handled;
2409
    }
2410
2411
    public boolean arrowScroll(int direction) {
2412
        View currentFocused = findFocus();
2413
        if (currentFocused == this) {
2414
            currentFocused = null;
2415
        } else if (currentFocused != null) {
2416
            boolean isChild = false;
2417
            for (ViewParent parent = currentFocused.getParent(); parent instanceof ViewGroup;
2418
                 parent = parent.getParent()) {
2419
                if (parent == this) {
2420
                    isChild = true;
2421
                    break;
2422
                }
2423
            }
2424
            if (!isChild) {
2425
                // This would cause the focus search down below to fail in fun ways.
2426
                final StringBuilder sb = new StringBuilder();
2427
                sb.append(currentFocused.getClass().getSimpleName());
2428
                for (ViewParent parent = currentFocused.getParent(); parent instanceof ViewGroup;
2429
                     parent = parent.getParent()) {
2430
                    sb.append(" => ").append(parent.getClass().getSimpleName());
2431
                }
2432
                Log.e(TAG, "arrowScroll tried to find focus based on non-child " +
2433
                        "current focused view " + sb.toString());
2434
                currentFocused = null;
2435
            }
2436
        }
2437
2438
        boolean handled = false;
2439
2440
        View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused,
2441
                direction);
2442
        if (nextFocused != null && nextFocused != currentFocused) {
2443
            if (direction == View.FOCUS_UP) {
2444
                // If there is nothing to the left, or this is causing us to
2445
                // jump to the right, then what we really want to do is page left.
2446
                final int nextTop = getChildRectInPagerCoordinates(mTempRect, nextFocused).top;
2447
                final int currTop = getChildRectInPagerCoordinates(mTempRect, currentFocused).top;
2448
                if (currentFocused != null && nextTop >= currTop) {
2449
                    handled = pageUp();
2450
                } else {
2451
                    handled = nextFocused.requestFocus();
2452
                }
2453
            } else if (direction == View.FOCUS_DOWN) {
2454
                // If there is nothing to the right, or this is causing us to
2455
                // jump to the left, then what we really want to do is page right.
2456
                final int nextDown = getChildRectInPagerCoordinates(mTempRect, nextFocused).bottom;
2457
                final int currDown = getChildRectInPagerCoordinates(mTempRect, currentFocused).bottom;
2458
                if (currentFocused != null && nextDown <= currDown) {
2459
                    handled = pageDown();
2460
                } else {
2461
                    handled = nextFocused.requestFocus();
2462
                }
2463
            }
2464
        } else if (direction == FOCUS_UP || direction == FOCUS_BACKWARD) {
2465
            // Trying to move left and nothing there; try to page.
2466
            handled = pageUp();
2467
        } else if (direction == FOCUS_DOWN || direction == FOCUS_FORWARD) {
2468
            // Trying to move right and nothing there; try to page.
2469
            handled = pageDown();
2470
        }
2471
        if (handled) {
2472
            playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
2473
        }
2474
        return handled;
2475
    }
2476
2477
    private Rect getChildRectInPagerCoordinates(Rect outRect, View child) {
2478
        if (outRect == null) {
2479
            outRect = new Rect();
2480
        }
2481
        if (child == null) {
2482
            outRect.set(0, 0, 0, 0);
2483
            return outRect;
2484
        }
2485
        outRect.left = child.getLeft();
2486
        outRect.right = child.getRight();
2487
        outRect.top = child.getTop();
2488
        outRect.bottom = child.getBottom();
2489
2490
        ViewParent parent = child.getParent();
2491
        while (parent instanceof ViewGroup && parent != this) {
2492
            final ViewGroup group = (ViewGroup) parent;
2493
            outRect.left += group.getLeft();
2494
            outRect.right += group.getRight();
2495
            outRect.top += group.getTop();
2496
            outRect.bottom += group.getBottom();
2497
2498
            parent = group.getParent();
2499
        }
2500
        return outRect;
2501
    }
2502
2503
    boolean pageUp() {
2504
        if (mCurItem > 0) {
2505
            setCurrentItem(mCurItem - 1, true);
2506
            return true;
2507
        }
2508
        return false;
2509
    }
2510
2511
    boolean pageDown() {
2512
        if (mAdapter != null && mCurItem < (mAdapter.getCount() - 1)) {
2513
            setCurrentItem(mCurItem + 1, true);
2514
            return true;
2515
        }
2516
        return false;
2517
    }
2518
2519
    /**
2520
     * We only want the current page that is being shown to be focusable.
2521
     */
2522
    @Override
2523
    public void addFocusables(ArrayList<View> views, int direction, int focusableMode) {
2524
        final int focusableCount = views.size();
2525
2526
        final int descendantFocusability = getDescendantFocusability();
2527
2528
        if (descendantFocusability != FOCUS_BLOCK_DESCENDANTS) {
2529
            for (int i = 0; i < getChildCount(); i++) {
2530
                final View child = getChildAt(i);
2531
                if (child.getVisibility() == VISIBLE) {
2532
                    ItemInfo ii = infoForChild(child);
2533
                    if (ii != null && ii.position == mCurItem) {
2534
                        child.addFocusables(views, direction, focusableMode);
2535
                    }
2536
                }
2537
            }
2538
        }
2539
2540
        // we add ourselves (if focusable) in all cases except for when we are
2541
        // FOCUS_AFTER_DESCENDANTS and there are some descendants focusable.  this is
2542
        // to avoid the focus search finding layouts when a more precise search
2543
        // among the focusable children would be more interesting.
2544
        if (
2545
                descendantFocusability != FOCUS_AFTER_DESCENDANTS ||
2546
                        // No focusable descendants
2547
                        (focusableCount == views.size())) {
2548
            // Note that we can't call the superclass here, because it will
2549
            // add all views in.  So we need to do the same thing View does.
2550
            if (!isFocusable()) {
2551
                return;
2552
            }
2553
            if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE &&
2554
                    isInTouchMode() && !isFocusableInTouchMode()) {
2555
                return;
2556
            }
2557
            if (views != null) {
2558
                views.add(this);
2559
            }
2560
        }
2561
    }
2562
2563
    /**
2564
     * We only want the current page that is being shown to be touchable.
2565
     */
2566
    @Override
2567
    public void addTouchables(ArrayList<View> views) {
2568
        // Note that we don't call super.addTouchables(), which means that
2569
        // we don't call View.addTouchables().  This is okay because a ViewPager
2570
        // is itself not touchable.
2571
        for (int i = 0; i < getChildCount(); i++) {
2572
            final View child = getChildAt(i);
2573
            if (child.getVisibility() == VISIBLE) {
2574
                ItemInfo ii = infoForChild(child);
2575
                if (ii != null && ii.position == mCurItem) {
2576
                    child.addTouchables(views);
2577
                }
2578
            }
2579
        }
2580
    }
2581
2582
    /**
2583
     * We only want the current page that is being shown to be focusable.
2584
     */
2585
    @Override
2586
    protected boolean onRequestFocusInDescendants(int direction,
2587
                                                  Rect previouslyFocusedRect) {
2588
        int index;
2589
        int increment;
2590
        int end;
2591
        int count = getChildCount();
2592
        if ((direction & FOCUS_FORWARD) != 0) {
2593
            index = 0;
2594
            increment = 1;
2595
            end = count;
2596
        } else {
2597
            index = count - 1;
2598
            increment = -1;
2599
            end = -1;
2600
        }
2601
        for (int i = index; i != end; i += increment) {
2602
            View child = getChildAt(i);
2603
            if (child.getVisibility() == VISIBLE) {
2604
                ItemInfo ii = infoForChild(child);
2605
                if (ii != null && ii.position == mCurItem) {
2606
                    if (child.requestFocus(direction, previouslyFocusedRect)) {
2607
                        return true;
2608
                    }
2609
                }
2610
            }
2611
        }
2612
        return false;
2613
    }
2614
2615
    @Override
2616
    public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
2617
        // Dispatch scroll events from this ViewPager.
2618
        if (event.getEventType() == AccessibilityEventCompat.TYPE_VIEW_SCROLLED) {
2619
            return super.dispatchPopulateAccessibilityEvent(event);
2620
        }
2621
2622
        // Dispatch all other accessibility events from the current page.
2623
        final int childCount = getChildCount();
2624
        for (int i = 0; i < childCount; i++) {
2625
            final View child = getChildAt(i);
2626
            if (child.getVisibility() == VISIBLE) {
2627
                final ItemInfo ii = infoForChild(child);
2628
                if (ii != null && ii.position == mCurItem &&
2629
                        child.dispatchPopulateAccessibilityEvent(event)) {
2630
                    return true;
2631
                }
2632
            }
2633
        }
2634
2635
        return false;
2636
    }
2637
2638
    @Override
2639
    protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
2640
        return new LayoutParams();
2641
    }
2642
2643
    @Override
2644
    protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
2645
        return generateDefaultLayoutParams();
2646
    }
2647
2648
    @Override
2649
    protected boolean checkLayoutParams(ViewGroup.LayoutParams p) {
2650
        return p instanceof LayoutParams && super.checkLayoutParams(p);
2651
    }
2652
2653
    @Override
2654
    public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
2655
        return new LayoutParams(getContext(), attrs);
2656
    }
2657
2658
    class MyAccessibilityDelegate extends AccessibilityDelegateCompat {
2659
2660
        @Override
2661
        public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
2662
            super.onInitializeAccessibilityEvent(host, event);
2663
            event.setClassName(ViewPager.class.getName());
2664
            final AccessibilityRecordCompat recordCompat = AccessibilityRecordCompat.obtain();
2665
            recordCompat.setScrollable(canScroll());
2666
            if (event.getEventType() == AccessibilityEventCompat.TYPE_VIEW_SCROLLED
2667
                    && mAdapter != null) {
2668
                recordCompat.setItemCount(mAdapter.getCount());
2669
                recordCompat.setFromIndex(mCurItem);
2670
                recordCompat.setToIndex(mCurItem);
2671
            }
2672
        }
2673
2674
        @Override
2675
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
2676
            super.onInitializeAccessibilityNodeInfo(host, info);
2677
            info.setClassName(ViewPager.class.getName());
2678
            info.setScrollable(canScroll());
2679
            if (internalCanScrollVertically(1)) {
2680
                info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD);
2681
            }
2682
            if (internalCanScrollVertically(-1)) {
2683
                info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD);
2684
            }
2685
        }
2686
2687
        @Override
2688
        public boolean performAccessibilityAction(View host, int action, Bundle args) {
2689
            if (super.performAccessibilityAction(host, action, args)) {
2690
                return true;
2691
            }
2692
            switch (action) {
2693
                case AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD: {
2694
                    if (internalCanScrollVertically(1)) {
2695
                        setCurrentItem(mCurItem + 1);
2696
                        return true;
2697
                    }
2698
                }
2699
                return false;
2700
                case AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD: {
2701
                    if (internalCanScrollVertically(-1)) {
2702
                        setCurrentItem(mCurItem - 1);
2703
                        return true;
2704
                    }
2705
                }
2706
                return false;
2707
            }
2708
            return false;
2709
        }
2710
2711
        private boolean canScroll() {
2712
            return (mAdapter != null) && (mAdapter.getCount() > 1);
2713
        }
2714
    }
2715
2716
    private class PagerObserver extends DataSetObserver {
2717
        @Override
2718
        public void onChanged() {
2719
            dataSetChanged();
2720
        }
2721
2722
        @Override
2723
        public void onInvalidated() {
2724
            dataSetChanged();
2725
        }
2726
    }
2727
2728
    /**
2729
     * Layout parameters that should be supplied for views added to a
2730
     * ViewPager.
2731
     */
2732
    public static class LayoutParams extends ViewGroup.LayoutParams {
2733
        /**
2734
         * true if this view is a decoration on the pager itself and not
2735
         * a view supplied by the adapter.
2736
         */
2737
        public boolean isDecor;
2738
2739
        /**
2740
         * Gravity setting for use on decor views only:
2741
         * Where to position the view page within the overall ViewPager
2742
         * container; constants are defined in {@link Gravity}.
2743
         */
2744
        public int gravity;
2745
2746
        /**
2747
         * Width as a 0-1 multiplier of the measured pager width
2748
         */
2749
        float heightFactor = 0.f;
2750
2751
        /**
2752
         * true if this view was added during layout and needs to be measured
2753
         * before being positioned.
2754
         */
2755
        boolean needsMeasure;
2756
2757
        /**
2758
         * Adapter position this view is for if !isDecor
2759
         */
2760
        int position;
2761
2762
        /**
2763
         * Current child index within the ViewPager that this view occupies
2764
         */
2765
        int childIndex;
2766
2767
        public LayoutParams() {
2768
            super(FILL_PARENT, FILL_PARENT);
2769
        }
2770
2771
        public LayoutParams(Context context, AttributeSet attrs) {
2772
            super(context, attrs);
2773
2774
            final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
2775
            gravity = a.getInteger(0, Gravity.TOP);
2776
            a.recycle();
2777
        }
2778
    }
2779
2780
    static class ViewPositionComparator implements Comparator<View> {
2781
        @Override
2782
        public int compare(View lhs, View rhs) {
2783
            final LayoutParams llp = (LayoutParams) lhs.getLayoutParams();
2784
            final LayoutParams rlp = (LayoutParams) rhs.getLayoutParams();
2785
            if (llp.isDecor != rlp.isDecor) {
2786
                return llp.isDecor ? 1 : -1;
2787
            }
2788
            return llp.position - rlp.position;
2789
        }
2790
    }
2791
}

+ 7 - 0
app/src/main/res/anim/bottom_in_anim.xml

@ -0,0 +1,7 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<set xmlns:android="http://schemas.android.com/apk/res/android">
3
    <translate
4
        android:duration="300"
5
        android:fromYDelta="100%p"
6
        android:toYDelta="0" />
7
</set>

+ 7 - 0
app/src/main/res/anim/bottom_out_anim.xml

@ -0,0 +1,7 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<set xmlns:android="http://schemas.android.com/apk/res/android">
3
    <translate
4
        android:duration="300"
5
        android:fromYDelta="0"
6
        android:toYDelta="100%p" />
7
</set>

app/src/main/res/drawable-xxhdpi/drawable-xxhdpi/mima.png → app/src/main/res/drawable-xxhdpi/mima.png


app/src/main/res/drawable-xxhdpi/drawable-xxhdpi/rentou.png → app/src/main/res/drawable-xxhdpi/rentou.png


app/src/main/res/drawable-xxhdpi/drawable-xxhdpi/shanche.png → app/src/main/res/drawable-xxhdpi/shanche.png


app/src/main/res/drawable-xxhdpi/drawable-xxhdpi/top.png → app/src/main/res/drawable-xxhdpi/top.png


app/src/main/res/drawable-xxhdpi/drawable-xxhdpi/tubiao1.png → app/src/main/res/drawable-xxhdpi/tubiao1.png


app/src/main/res/drawable-xxhdpi/drawable-xxhdpi/zhuangtailan.png → app/src/main/res/drawable-xxhdpi/zhuangtailan.png


app/src/main/res/drawable-xxhdpi/drawable-xxhdpi/zhucaozuolan.png → app/src/main/res/drawable-xxhdpi/zhucaozuolan.png


+ 12 - 0
app/src/main/res/drawable/bg_bottom_dialog.xml

@ -0,0 +1,12 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:shape="rectangle">
4
5
    <corners
6
        android:topLeftRadius="6dp"
7
        android:topRightRadius="6dp" />
8
9
    <solid android:color="#424242" />
10
11
12
</shape>

+ 10 - 0
app/src/main/res/drawable/bg_comment_report.xml

@ -0,0 +1,10 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:shape="rectangle">
4
5
    <corners android:radius="15dp" />
6
7
    <solid android:color="#606060" />
8
9
10
</shape>

+ 10 - 0
app/src/main/res/drawable/bg_topic.xml

@ -0,0 +1,10 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:shape="rectangle">
4
5
    <corners android:radius="6dp" />
6
7
    <solid android:color="#b3303030" />
8
9
10
</shape>

+ 48 - 0
app/src/main/res/layout/activity_videodetails.xml

@ -0,0 +1,48 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="match_parent"
4
    android:layout_height="match_parent"
5
    android:background="#424242">
6
7
8
    <com.electric.chargingpile.view.sview.VerticalViewPager
9
        android:id="@+id/pager_video"
10
        android:layout_width="match_parent"
11
        android:layout_height="match_parent" />
12
13
14
    <RelativeLayout
15
        android:layout_width="match_parent"
16
        android:layout_height="48dp">
17
18
19
        <TextView
20
            android:id="@+id/vd_title_tv"
21
            android:layout_width="wrap_content"
22
            android:layout_height="wrap_content"
23
            android:layout_centerInParent="true"
24
            android:text="待问答问题"
25
            android:textColor="#ffffff"
26
            android:textSize="18sp" />
27
28
29
        <ImageView
30
            android:id="@+id/vd_title_back"
31
            android:layout_width="wrap_content"
32
            android:layout_height="match_parent"
33
            android:layout_alignParentLeft="true"
34
            android:paddingLeft="15dp"
35
            android:paddingRight="15dp"
36
            android:src="@drawable/tubiao1" />
37
38
        <ImageView
39
            android:id="@+id/vd_title_dot"
40
            android:layout_width="wrap_content"
41
            android:layout_height="match_parent"
42
            android:layout_alignParentRight="true"
43
            android:paddingLeft="15dp"
44
            android:paddingRight="15dp"
45
            android:src="@drawable/tubiao1" />
46
47
    </RelativeLayout>
48
</RelativeLayout>

+ 11 - 0
app/src/main/res/layout/fragment_shortvideo.xml

@ -0,0 +1,11 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="match_parent"
4
    android:layout_height="match_parent">
5
6
    <com.electric.chargingpile.view.sview.VerticalViewPager
7
        android:id="@+id/pager_video"
8
        android:layout_width="match_parent"
9
        android:layout_height="match_parent" />
10
11
</android.support.constraint.ConstraintLayout>

+ 130 - 0
app/src/main/res/layout/item_show_comment.xml

@ -0,0 +1,130 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="match_parent"
4
    android:layout_height="wrap_content"
5
    android:layout_marginTop="20dp">
6
7
    <LinearLayout
8
        android:id="@+id/item_user_comment_like"
9
        android:layout_width="wrap_content"
10
        android:layout_height="18dp"
11
        android:layout_alignParentEnd="true"
12
        android:layout_marginTop="3dp"
13
        android:layout_marginEnd="19dp"
14
        android:gravity="center_vertical">
15
16
        <ImageView
17
            android:id="@+id/item_user_like_img"
18
            android:layout_width="18dp"
19
            android:layout_height="18dp"
20
            android:background="#fff" />
21
22
        <TextView
23
            android:id="@+id/item_user_like_count"
24
            android:layout_width="wrap_content"
25
            android:layout_height="wrap_content"
26
            android:layout_marginStart="4dp"
27
            android:text="1000"
28
            android:textColor="#888"
29
            android:textSize="12sp" />
30
    </LinearLayout>
31
32
33
    <ImageView
34
        android:id="@+id/item_user_avatar"
35
        android:layout_width="20dp"
36
        android:layout_height="20dp"
37
        android:layout_marginStart="15dp"
38
        android:layout_marginTop="6dp"
39
        android:background="#3df" />
40
41
42
    <TextView
43
        android:id="@+id/item_user_name"
44
        android:layout_width="wrap_content"
45
        android:layout_height="wrap_content"
46
        android:layout_marginStart="5dp"
47
        android:layout_toEndOf="@+id/item_user_avatar"
48
        android:text="12sp12sp12sp"
49
        android:textColor="#fff"
50
        android:textSize="12sp" />
51
52
    <TextView
53
        android:id="@+id/item_user_time"
54
        android:layout_width="wrap_content"
55
        android:layout_height="wrap_content"
56
        android:layout_below="@+id/item_user_name"
57
        android:layout_alignStart="@+id/item_user_name"
58
        android:layout_marginStart="5dp"
59
        android:text="12sp12sp12sp"
60
        android:textColor="#888"
61
        android:textSize="12sp" />
62
63
64
    <TextView
65
        android:id="@+id/item_user_con"
66
        android:layout_width="wrap_content"
67
        android:layout_height="wrap_content"
68
        android:layout_below="@+id/item_user_time"
69
        android:layout_alignStart="@+id/item_user_name"
70
        android:layout_marginStart="5dp"
71
        android:layout_marginTop="10dp"
72
        android:text="12sp12sp12sp"
73
        android:textColor="#fff"
74
        android:textSize="14sp" />
75
76
    <LinearLayout
77
        android:id="@+id/item_user_operation"
78
        android:layout_width="wrap_content"
79
        android:layout_height="22dp"
80
        android:layout_below="@+id/item_user_con"
81
        android:layout_alignStart="@+id/item_user_name"
82
        android:layout_marginTop="10dp"
83
        android:layout_marginBottom="22dp"
84
        android:gravity="center_vertical">
85
86
        <LinearLayout
87
            android:id="@+id/item_user_report_ll"
88
            android:layout_width="wrap_content"
89
            android:layout_height="match_parent"
90
            android:layout_marginEnd="10dp"
91
            android:background="@drawable/bg_comment_report"
92
            android:gravity="center_vertical">
93
94
            <ImageView
95
                android:layout_width="16dp"
96
                android:layout_height="16dp"
97
                android:layout_marginStart="9dp"
98
                android:background="#fff" />
99
100
            <TextView
101
                android:id="@+id/item_user_report_count"
102
                android:layout_width="wrap_content"
103
                android:layout_height="wrap_content"
104
                android:layout_marginStart="5dp"
105
                android:layout_marginEnd="9dp"
106
                android:text="1000回复"
107
                android:textColor="#c2c2c2"
108
                android:textSize="12sp" />
109
        </LinearLayout>
110
111
112
        <TextView
113
            android:id="@+id/item_user_delete"
114
            android:layout_width="wrap_content"
115
            android:layout_height="22dp"
116
            android:gravity="center"
117
            android:text="删除"
118
            android:textColor="#c2c2c2"
119
            android:textSize="12sp" />
120
    </LinearLayout>
121
122
    <View
123
        android:layout_width="match_parent"
124
        android:layout_height="1dp"
125
        android:layout_below="@+id/item_user_operation"
126
        android:layout_marginStart="16dp"
127
        android:background="#505050" />
128
129
130
</RelativeLayout>

+ 85 - 0
app/src/main/res/layout/sv_video_publish_info.xml

@ -0,0 +1,85 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="match_parent"
4
    android:layout_height="wrap_content"
5
    android:background="@drawable/bg_bottom_dialog">
6
7
8
    <View
9
        android:id="@+id/video_publish_close"
10
        android:layout_width="22dp"
11
        android:layout_height="22dp"
12
        android:layout_alignParentEnd="true"
13
        android:layout_marginTop="14dp"
14
        android:layout_marginEnd="14dp"
15
        android:background="#fff" />
16
17
18
    <LinearLayout
19
        android:id="@+id/video_publish_topic"
20
        android:layout_width="wrap_content"
21
        android:layout_height="wrap_content"
22
        android:layout_marginStart="15dp"
23
        android:layout_marginTop="15dp"
24
        android:layout_marginEnd="40dp"
25
        android:layout_marginBottom="10dp"
26
        android:background="@drawable/bg_topic"
27
        android:gravity="center_vertical"
28
        android:minHeight="30dp">
29
30
        <View
31
            android:layout_width="12dp"
32
            android:layout_height="12dp"
33
            android:layout_marginStart="12dp"
34
            android:layout_marginEnd="4dp"
35
            android:background="#fff" />
36
37
        <TextView
38
            android:id="@+id/video_publish_topic_con"
39
            android:layout_width="wrap_content"
40
            android:layout_height="wrap_content"
41
            android:layout_margin="5dp"
42
            android:text="显示出所有文字内容显示出所有文字内容显示出所有文字内容"
43
            android:textColor="#fff"
44
            android:textSize="11sp" />
45
    </LinearLayout>
46
47
    <LinearLayout
48
        android:id="@+id/video_publish_user_ll"
49
        android:layout_width="wrap_content"
50
        android:layout_height="20dp"
51
        android:layout_below="@+id/video_publish_topic"
52
        android:layout_marginStart="15dp"
53
        android:gravity="center_vertical"
54
        android:orientation="horizontal">
55
56
        <ImageView
57
            android:id="@+id/video_publish_user_avatar"
58
            android:layout_width="20dp"
59
            android:layout_height="20dp"
60
            android:background="#3df" />
61
62
        <TextView
63
            android:id="@+id/video_publish_user_name"
64
            android:layout_width="wrap_content"
65
            android:layout_height="wrap_content"
66
            android:layout_marginStart="6dp"
67
            android:text="12sp12sp12sp"
68
            android:textColor="#fff"
69
            android:textSize="12sp" />
70
    </LinearLayout>
71
72
    <TextView
73
        android:layout_width="match_parent"
74
        android:layout_height="wrap_content"
75
        android:layout_below="@+id/video_publish_user_ll"
76
        android:layout_marginStart="30dp"
77
        android:layout_marginTop="15dp"
78
        android:layout_marginEnd="30dp"
79
        android:layout_marginBottom="35dp"
80
        android:maxHeight="320dp"
81
        android:text="asfsfsfsfsfsafsafsfsfsaf"
82
        android:textColor="#fff"
83
        android:textSize="14sp" />
84
85
</RelativeLayout>

+ 204 - 0
app/src/main/res/layout/view_show_bottom.xml

@ -0,0 +1,204 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<merge xmlns:android="http://schemas.android.com/apk/res/android">
3
4
    <RelativeLayout
5
        android:id="@+id/sv_show_bottom"
6
        android:layout_width="match_parent"
7
        android:layout_height="50dp"
8
        android:layout_alignParentBottom="true">
9
10
        <LinearLayout
11
            android:id="@+id/sv_show_forward"
12
            android:layout_width="wrap_content"
13
            android:layout_height="30dp"
14
            android:layout_alignParentRight="true"
15
            android:layout_centerVertical="true"
16
            android:layout_marginRight="15dp"
17
            android:gravity="center_vertical">
18
19
            <ImageView
20
                android:layout_width="30dp"
21
                android:layout_height="30dp"
22
                android:layout_centerVertical="true"
23
                android:background="#fff" />
24
25
            <TextView
26
                android:layout_width="wrap_content"
27
                android:layout_height="wrap_content"
28
                android:text="转发"
29
                android:textSize="12sp" />
30
31
        </LinearLayout>
32
33
        <LinearLayout
34
            android:id="@+id/sv_show_comment_count_ll"
35
            android:layout_width="wrap_content"
36
            android:layout_height="30dp"
37
            android:layout_centerVertical="true"
38
            android:layout_marginRight="15dp"
39
            android:layout_toStartOf="@+id/sv_show_forward"
40
            android:gravity="center_vertical">
41
42
            <ImageView
43
                android:layout_width="30dp"
44
                android:layout_height="30dp"
45
                android:layout_centerVertical="true"
46
                android:background="#fff" />
47
48
            <TextView
49
                android:id="@+id/sv_show_comment_count_tv"
50
                android:layout_width="wrap_content"
51
                android:layout_height="wrap_content"
52
                android:text="1230w"
53
                android:textSize="12sp" />
54
55
        </LinearLayout>
56
57
        <LinearLayout
58
            android:id="@+id/sv_show_like_ll"
59
            android:layout_width="wrap_content"
60
            android:layout_height="30dp"
61
            android:layout_centerVertical="true"
62
            android:layout_marginRight="15dp"
63
            android:layout_toStartOf="@+id/sv_show_comment_count_ll"
64
            android:gravity="center_vertical">
65
66
            <ImageView
67
                android:id="@+id/sv_show_like_img"
68
                android:layout_width="30dp"
69
                android:layout_height="30dp"
70
                android:layout_centerVertical="true"
71
                android:background="#fff" />
72
73
            <TextView
74
                android:id="@+id/sv_show_like_tv"
75
                android:layout_width="wrap_content"
76
                android:layout_height="wrap_content"
77
                android:text="12我30w"
78
                android:textSize="12sp" />
79
80
        </LinearLayout>
81
82
        <LinearLayout
83
            android:id="@+id/sv_show_comment_ll"
84
            android:layout_width="match_parent"
85
            android:layout_height="match_parent"
86
            android:layout_centerVertical="true"
87
            android:layout_marginRight="15dp"
88
            android:layout_toStartOf="@+id/sv_show_like_ll"
89
            android:gravity="center_vertical">
90
91
            <ImageView
92
                android:layout_width="30dp"
93
                android:layout_height="30dp"
94
                android:layout_centerVertical="true"
95
                android:layout_marginLeft="15dp"
96
                android:background="#fff" />
97
98
            <TextView
99
                android:layout_width="wrap_content"
100
                android:layout_height="wrap_content"
101
                android:text="写评论"
102
                android:textSize="12sp" />
103
104
        </LinearLayout>
105
106
    </RelativeLayout>
107
108
    <View
109
        android:layout_width="match_parent"
110
        android:layout_height="1dp"
111
        android:layout_above="@+id/sv_show_bottom"
112
        android:background="#505050" />
113
114
    <TextView
115
        android:id="@+id/sv_show_tvcon"
116
        android:layout_width="match_parent"
117
        android:layout_height="wrap_content"
118
        android:layout_above="@+id/sv_show_bottom"
119
        android:layout_marginLeft="39dp"
120
        android:layout_marginRight="39dp"
121
        android:layout_marginBottom="23dp"
122
        android:ellipsize="end"
123
        android:maxLines="3"
124
        android:text="3-超出三行的,点击文字,上滑弹窗,显示出所有文字内容,根据内容自适应高度,最高为一半屏幕高度,字数超高,以滚动条滑动显示。3-超出三行的,点击文字,上滑弹窗,显示出所有文字内容,根据内容自适应高度,最高为一半屏幕高度,字数超高,以滚动条滑动显示。"
125
        android:textSize="14sp" />
126
127
    <View
128
        android:id="@+id/sv_show_tvcon_more"
129
        android:layout_width="30dp"
130
        android:layout_height="30dp"
131
        android:layout_above="@+id/sv_show_bottom"
132
        android:layout_alignParentEnd="true"
133
        android:layout_marginBottom="28dp"
134
        android:background="@color/__picker_black_40" />
135
136
    <RelativeLayout
137
        android:id="@+id/sv_show_user_info"
138
        android:layout_width="wrap_content"
139
        android:layout_height="34dp"
140
        android:layout_above="@+id/sv_show_tvcon"
141
        android:layout_marginLeft="15dp"
142
        android:layout_marginBottom="5dp"
143
        android:background="#2ff">
144
145
        <ImageView
146
            android:id="@+id/sv_show_user_avatar"
147
            android:layout_width="20dp"
148
            android:layout_height="20dp"
149
            android:layout_centerVertical="true"
150
            android:background="#fff" />
151
152
        <TextView
153
            android:id="@+id/sv_show_user_name"
154
            android:layout_width="wrap_content"
155
            android:layout_height="wrap_content"
156
            android:layout_marginLeft="5dp"
157
            android:layout_toEndOf="@+id/sv_show_user_avatar"
158
            android:text="adsdasasdad"
159
            android:textColor="#fff"
160
            android:textSize="12sp" />
161
162
        <TextView
163
            android:id="@+id/sv_show_user_time"
164
            android:layout_width="wrap_content"
165
            android:layout_height="wrap_content"
166
            android:layout_below="@+id/sv_show_user_name"
167
            android:layout_alignLeft="@+id/sv_show_user_name"
168
            android:text="adsdasasdad"
169
            android:textColor="#fff"
170
            android:textSize="12sp" />
171
    </RelativeLayout>
172
173
174
    <LinearLayout
175
        android:id="@+id/sv_show_topic"
176
        android:layout_width="wrap_content"
177
        android:layout_height="30dp"
178
        android:layout_above="@+id/sv_show_user_info"
179
        android:layout_marginStart="15dp"
180
        android:layout_marginEnd="15dp"
181
        android:layout_marginBottom="10dp"
182
        android:background="#b3303030"
183
        android:gravity="center_vertical">
184
185
        <View
186
            android:layout_width="12dp"
187
            android:layout_height="12dp"
188
            android:layout_marginStart="12dp"
189
            android:layout_marginEnd="4dp"
190
            android:background="#fff" />
191
192
        <TextView
193
            android:id="@+id/sv_show_topic_con"
194
            android:layout_width="wrap_content"
195
            android:layout_height="wrap_content"
196
            android:layout_marginRight="12dp"
197
            android:ellipsize="end"
198
            android:maxLines="1"
199
            android:text="显示出所有文字内容显示出所有文字内容显示出所有文字内容显示出所有文字内容显示出所有文字内容显示出所有文字内容显示出所有文字内容"
200
            android:textColor="#fff"
201
            android:textSize="11sp" />
202
    </LinearLayout>
203
204
</merge>

+ 74 - 0
app/src/main/res/layout/view_show_comment.xml

@ -0,0 +1,74 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="match_parent"
4
    android:layout_height="wrap_content"
5
    android:background="@drawable/bg_bottom_dialog">
6
7
    <TextView
8
        android:id="@+id/show_comment_title"
9
        android:layout_width="wrap_content"
10
        android:layout_height="wrap_content"
11
        android:layout_centerHorizontal="true"
12
        android:layout_marginTop="10dp"
13
        android:text="12sp12sp12sp"
14
        android:textColor="#c2c2c2"
15
        android:textSize="14sp" />
16
17
18
    <View
19
        android:id="@+id/show_comment_close"
20
        android:layout_width="22dp"
21
        android:layout_height="22dp"
22
        android:layout_alignParentEnd="true"
23
        android:layout_marginTop="9dp"
24
        android:layout_marginEnd="14dp"
25
        android:background="#fff" />
26
27
    <View
28
        android:layout_width="match_parent"
29
        android:layout_height="1dp"
30
        android:layout_marginTop="40dp"
31
        android:background="#505050" />
32
33
    <android.support.v7.widget.RecyclerView
34
        android:id="@+id/show_comment_lv"
35
        android:layout_width="wrap_content"
36
        android:layout_height="320dp"
37
        android:layout_marginBottom="54dp"
38
        android:layout_marginTop="40dp" />
39
40
    <LinearLayout
41
        android:layout_width="match_parent"
42
        android:layout_height="wrap_content"
43
        android:layout_below="@+id/show_comment_lv"
44
        android:background="#535353"
45
        android:layout_marginTop="-54dp"
46
        android:gravity="center_vertical"
47
        android:minHeight="54dp">
48
49
        <EditText
50
            android:id="@+id/show_comment_ed"
51
            android:layout_width="0dp"
52
            android:layout_height="wrap_content"
53
            android:layout_marginStart="14dp"
54
            android:layout_weight="1"
55
            android:background="@drawable/bg_comment_report"
56
            android:hint="写评论"
57
            android:minHeight="30dp"
58
            android:paddingStart="14dp"
59
            android:paddingEnd="14dp"
60
            android:textColorHint="#7e7e7e" />
61
62
        <TextView
63
            android:id="@+id/show_comment_publish"
64
            android:layout_width="wrap_content"
65
            android:layout_height="match_parent"
66
            android:gravity="center"
67
            android:paddingStart="13dp"
68
            android:paddingEnd="13dp"
69
            android:text="发布"
70
            android:textColor="#7e7e7e"
71
            android:textSize="14sp" />
72
    </LinearLayout>
73
74
</RelativeLayout>

+ 13 - 0
app/src/main/res/layout/view_show_view.xml

@ -0,0 +1,13 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="match_parent"
4
    android:layout_height="match_parent">
5
6
    <ImageView
7
        android:layout_width="match_parent"
8
        android:layout_height="match_parent"
9
        android:background="#fff0" />
10
11
    <include layout="@layout/view_show_bottom" />
12
13
</RelativeLayout>

+ 15 - 0
app/src/main/res/layout/view_show_zoom.xml

@ -0,0 +1,15 @@
1
<?xml version="1.0" encoding="utf-8"?>
2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="match_parent"
4
    android:layout_height="match_parent">
5
6
7
    <com.electric.chargingpile.widge.photoview.ZoomingViewpager
8
        android:id="@+id/view_show_zoomingphoto"
9
        android:layout_width="match_parent"
10
        android:layout_height="match_parent" />
11
12
13
    <include layout="@layout/view_show_bottom" />
14
15
</RelativeLayout>

+ 2 - 0
app/src/main/res/values/color.xml

@ -170,6 +170,8 @@
170 170
    <color name="color_888888">#888888</color>
171 171
    <color name="color_fb9349">#fb9349</color>
172 172

173
    <color name="sv_black">#FF000000</color>
174
    <color name="sv_white">#FFFFFF</color>
173 175

174 176

175 177


+ 12 - 0
app/src/main/res/values/strings.xml

@ -192,4 +192,16 @@
192 192
193 193
    <string name="refund_tip">退款说明:\n1、可退款金额为实际充值金额,不含充值赠送、添加站点赠送和活动赠送金额。申请退款时,赠送金额将清零,请慎重选择;\n2、退款过程中,账户将被冻结,无法充值,使用支付宝免密支付充电不受影响;\n3、微信充值订单6个月内,支付宝充值订单3个月内将原路返回,超出时间我们将联系您取得新的退款方式;\n4、退款将于3-7个工作日内完成,请耐心等待。</string>
194 194
195
196
    <string name="refresh_pull_to_refresh">Slide down to refresh</string>
197
    <string name="refresh_release_to_refresh">Release to refresh</string>
198
    <string name="refresh_refreshing">Refreshing...</string>
199
    <string name="refresh_succeed">Refreshed</string>
200
    <string name="refresh_fail">Refreshing failed</string>
201
    <string name="refresh_pullup_to_load">Slide up to upload more</string>
202
    <string name="refresh_release_to_load">Release to upload</string>
203
    <string name="refresh_loading">Loading...</string>
204
    <string name="refresh_load_succeed">Loading succeeded</string>
205
    <string name="refresh_load_succeed_nomore">That\'s All!</string>
206
    <string name="refresh_load_fail">Loading failed</string>
195 207
</resources>

+ 30 - 9
app/src/main/res/values/styles.xml

@ -1,4 +1,5 @@
1 1
<resources>
2

2 3
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
3 4
        <item name="colorPrimary">@color/colorPrimary</item>
4 5
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
@ -55,18 +56,18 @@
55 56
    <style name="Widget.ProgressBar.RegularProgressBar">
56 57
        <item name="android:indeterminateOnly">false</item>
57 58
        <item name="android:progressDrawable">@drawable/progressbar</item>
58
        <item name="android:indeterminateDrawable">@android:drawable/progress_indeterminate_horizontal</item>
59
        <item name="android:indeterminateDrawable">
60
            @android:drawable/progress_indeterminate_horizontal
61
        </item>
59 62
        <item name="android:minHeight">1dip</item>
60 63
        <item name="android:maxHeight">10dip</item>
61 64
    </style>
62 65

63 66

64
        <!--<style name="MyRatingBar" parent="@android:style/Widget.RatingBar">-->
65
            <!--<item name="android:progressDrawable">@drawable/circle_rating_bar_full</item>-->
66

67
        <!--</style>-->
68

67
    <!--<style name="MyRatingBar" parent="@android:style/Widget.RatingBar">-->
68
    <!--<item name="android:progressDrawable">@drawable/circle_rating_bar_full</item>-->
69 69

70
    <!--</style>-->
70 71

71 72

72 73
    <style name="roomRatingBar" parent="@android:style/Widget.RatingBar">
@ -82,8 +83,6 @@
82 83
    </style>
83 84

84 85

85

86

87 86
    <style name="appointent_time_item_style">
88 87
        <item name="android:textColor">@drawable/appointent_item_tv_color_selector</item>
89 88
        <item name="android:layout_width">fill_parent</item>
@ -191,16 +190,19 @@
191 190
        <item name="android:windowBackground">@android:color/transparent</item>
192 191
        <item name="android:windowContentOverlay">@null</item>
193 192
    </style>
194
    <style name="dialogAnim" parent="android:Animation" >
193

194
    <style name="dialogAnim" parent="android:Animation">
195 195
        <item name="android:windowEnterAnimation">@anim/dialog_show</item>
196 196
        <item name="android:windowExitAnimation">@anim/dialog_dismiss</item>
197 197
    </style>
198

198 199
    <style name="divider_horizontal"><!-- 水平分割线 -->
199 200
        <item name="android:layout_width">fill_parent</item>
200 201
        <item name="android:layout_height">0.01dp</item>
201 202
        <item name="android:background">@android:color/darker_gray</item>
202 203
        <item name="android:orientation">vertical</item>
203 204
    </style>
205

204 206
    <style name="divider_vertical"><!-- 垂直分割线 -->
205 207
        <item name="android:layout_width">0.01dp</item>
206 208
        <item name="android:layout_height">fill_parent</item>
@ -220,6 +222,25 @@
220 222
        <item name="android:windowCloseOnTouchOutside">false</item>
221 223
    </style>
222 224

225

226
    <style name="bottomDialogStyle">
227
        <item name="android:windowBackground">@android:color/transparent</item>
228
        <item name="android:windowContentOverlay">@null</item>
229
        <item name="android:windowIsFloating">true</item>
230
        <item name="android:windowFrame">@null</item>
231
        <item name="android:backgroundDimEnabled">false</item>
232
        <item name="android:windowNoTitle">true</item>
233
        <item name="android:windowIsTranslucent">true</item>
234
        <item name="android:windowCloseOnTouchOutside">true</item>
235
        <item name="android:windowAnimationStyle">@style/BottomDialogAnimation</item>
236
    </style>
237

238
    <style name="BottomDialogAnimation">
239
        <item name="android:windowEnterAnimation">@anim/bottom_in_anim</item>
240
        <item name="android:windowExitAnimation">@anim/bottom_out_anim</item>
241
    </style>
242

243

223 244
    <style name="AnimationPreview">
224 245
        <item name="android:windowEnterAnimation">@anim/fade_in</item>
225 246
        <item name="android:windowExitAnimation">@anim/fade_out</item>