app/build.gradle
@@ -148,5 +148,6 @@ //圆形头像 implementation 'de.hdodenhof:circleimageview:3.1.0' //广播通信 implementation 'io.github.jeremyliao:live-event-bus-x:1.8.0' } app/src/main/AndroidManifest.xml
@@ -33,16 +33,17 @@ <application android:name=".MyApplication" android:allowBackup="true" android:dataExtractionRules="@xml/data_extraction_rules" android:fullBackupContent="@xml/backup_rules" android:hardwareAccelerated="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.PipIrrApp" android:usesCleartextTraffic="true" android:hardwareAccelerated="true" tools:targetApi="31"> <!-- 告知 XXPermissions 当前项目已经适配了分区存储特性 --> <meta-data @@ -58,7 +59,8 @@ <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <!-- <activity android:name=".activity.MainActivity" />--> <activity android:name=".activity.ChangePSActivity" /> <!-- <activity android:name=".activity.MainActivity" />--> <!-- Required since 5.2.0 --> <!-- 新的 tag/alias 接口结果返回需要开发者配置一个自定义的Service --> <!-- 3.3.0开始所有事件将通过该类回调 --> app/src/main/java/com/dayu/pipirrapp/MyApplication.java
@@ -2,6 +2,7 @@ import android.app.Application; import com.dayu.pipirrapp.net.ApiManager; import com.tencent.bugly.crashreport.CrashReport; import cn.jpush.android.api.JPushInterface; @@ -19,6 +20,9 @@ public void onCreate() { super.onCreate(); myApplication = this; ApiManager.init(); JPushInterface.setDebugMode(true); JPushInterface.init(this); CrashReport.initCrashReport(getApplicationContext(), "3d4bcf7046", false); app/src/main/java/com/dayu/pipirrapp/activity/ChangePSActivity.java
New file @@ -0,0 +1,27 @@ package com.dayu.pipirrapp.activity; import android.os.Bundle; import android.view.LayoutInflater; import androidx.annotation.Nullable; import com.dayu.pipirrapp.databinding.ActivityChangePassWordBinding; import com.dayu.pipirrapp.view.TitleBar; /** * author: zuo * Date: 2024-01-29 * Time: 17:19 * 备注:修改密码 */ public class ChangePSActivity extends BaseActivity { ActivityChangePassWordBinding binding; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); binding = ActivityChangePassWordBinding.inflate(LayoutInflater.from(this)); new TitleBar(this).setTitleText("修改密码"); setContentView(binding.getRoot()); } } app/src/main/java/com/dayu/pipirrapp/activity/LoginActivity.java
@@ -43,6 +43,7 @@ startActivity(intent); this.finish(); }); } private void togglePasswordVisibility() { app/src/main/java/com/dayu/pipirrapp/bean/LatLonBean.java
New file @@ -0,0 +1,28 @@ package com.dayu.pipirrapp.bean; /** * author: zuo * Date: 2024-01-26 * Time: 16:15 * 备注:经纬度 */ public class LatLonBean { double latitude; double longitude; public double getLatitude() { return latitude; } public void setLatitude(double latitude) { this.latitude = latitude; } public double getLongitude() { return longitude; } public void setLongitude(double longitude) { this.longitude = longitude; } } app/src/main/java/com/dayu/pipirrapp/bean/WeatherResponse.java
New file @@ -0,0 +1,249 @@ package com.dayu.pipirrapp.bean; /** * author: zuo * Date: 2024-01-26 * Time: 10:23 * 备注:天气接口返回的实例 */ public class WeatherResponse { private Result[] results; private String date; public String getDate() { return date; } public void setDate(String date) { this.date = date; } public Result[] getResults() { return results; } public void setResults(Result[] value) { this.results = value; } public class Result { public Daily[] daily; //返回指定days天数的结果 public String last_update; public Location location; public Daily[] getDaily() { return daily; } public void setDaily(Daily[] value) { this.daily = value; } public String getLast_update() { return last_update; } public void setLast_update(String last_update) { this.last_update = last_update; } public Location getLocation() { return location; } public void setLocation(Location value) { this.location = value; } } public class Daily { private String code_day; //白天天气现象代码 private String code_night;//晚间天气现象代码 private String date;//日期(该城市的本地时间) private String high;//当天最高温度 private String humidity; //相对湿度,0~100,单位为百分比 private String low;//当天最低温度 private String precip;//降水概率,范围0~1,单位百分比(目前仅支持国外城市) private String rainfall; //降水量,单位mm private String text_day; //白天天气现象文字 private String text_night;//晚间天气现象文字 private String wind_direction;//风向文字 private String wind_direction_degree;//风向角度,范围0~360 private String wind_scale;//风力等级 private String wind_speed;//风速,单位km/h(当unit=c时)、mph(当unit=f时) public String getCode_day() { return code_day; } public void setCode_day(String code_day) { this.code_day = code_day; } public String getCode_night() { return code_night; } public void setCode_night(String code_night) { this.code_night = code_night; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } public String getHigh() { return high; } public void setHigh(String high) { this.high = high; } public String getHumidity() { return humidity; } public void setHumidity(String humidity) { this.humidity = humidity; } public String getLow() { return low; } public void setLow(String low) { this.low = low; } public String getPrecip() { return precip; } public void setPrecip(String precip) { this.precip = precip; } public String getRainfall() { return rainfall; } public void setRainfall(String rainfall) { this.rainfall = rainfall; } public String getText_day() { return text_day; } public void setText_day(String text_day) { this.text_day = text_day; } public String getText_night() { return text_night; } public void setText_night(String text_night) { this.text_night = text_night; } public String getWind_direction() { return wind_direction; } public void setWind_direction(String wind_direction) { this.wind_direction = wind_direction; } public String getWind_direction_degree() { return wind_direction_degree; } public void setWind_direction_degree(String wind_direction_degree) { this.wind_direction_degree = wind_direction_degree; } public String getWind_scale() { return wind_scale; } public void setWind_scale(String wind_scale) { this.wind_scale = wind_scale; } public String getWind_speed() { return wind_speed; } public void setWind_speed(String wind_speed) { this.wind_speed = wind_speed; } } public class Location { private String country; private String id; private String name; private String path; private String timezone; private String timezoneOffset; public String getCountry() { return country; } public void setCountry(String value) { this.country = value; } public String getid() { return id; } public void setid(String value) { this.id = value; } public String getName() { return name; } public void setName(String value) { this.name = value; } public String getPath() { return path; } public void setPath(String value) { this.path = value; } public String getTimezone() { return timezone; } public void setTimezone(String value) { this.timezone = value; } public String getTimezoneOffset() { return timezoneOffset; } public void setTimezoneOffset(String value) { this.timezoneOffset = value; } } } app/src/main/java/com/dayu/pipirrapp/fragment/MainFragment.java
@@ -1,15 +1,121 @@ package com.dayu.pipirrapp.fragment; import android.os.Bundle; import android.os.Looper; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.lifecycle.Observer; import com.dayu.pipirrapp.bean.LatLonBean; import com.dayu.pipirrapp.bean.WeatherResponse; import com.dayu.pipirrapp.databinding.FragmentMainBinding; import com.dayu.pipirrapp.net.ApiManager; import com.dayu.pipirrapp.utils.ImageUtils; import com.dayu.pipirrapp.utils.MyJsonParser; import com.dayu.pipirrapp.utils.SharedPreferencesHelper; import com.jeremyliao.liveeventbus.LiveEventBus; import com.tencent.bugly.crashreport.CrashReport; import java.util.Calendar; import java.util.Date; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; /** * author: zuo * Date: 2023/12/20 * Time: 10:12 * 备注:首页 */ public class MainFragment extends BaseFragment{ public class MainFragment extends BaseFragment { FragmentMainBinding binding; WeatherResponse weatherResponse; //收到定位广播后获取天气信息 Observer<LatLonBean> myObserver = new Observer<LatLonBean>() { @Override public void onChanged(LatLonBean latLonBean) { String jsonStr = SharedPreferencesHelper.getInstance(MainFragment.this.getActivity()).get("WeatherResponse", ""); weatherResponse = MyJsonParser.getBeanFromJson(jsonStr, WeatherResponse.class); if (weatherResponse == null) { weatherResponse = new WeatherResponse(); } // 获取当前时间 Calendar calendar = Calendar.getInstance(); // 获取当前年月日 int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH) + 1; // 注意月份是从0开始计数的,所以要加1 int day = calendar.get(Calendar.DAY_OF_MONTH); String date = year + "年" + month + "月" + day + "日"; if (weatherResponse == null || !date.equals(weatherResponse.getDate())) { weatherResponse.setDate(date); ApiManager.getInstance().requestWeather(latLonBean.getLatitude() + ":" + latLonBean.getLongitude(), new Callback<WeatherResponse>() { @Override public void onResponse(Call<WeatherResponse> call, Response<WeatherResponse> response) { if (response.isSuccessful()) { weatherResponse.setResults(response.body().getResults()); SharedPreferencesHelper.getInstance(MainFragment.this.getActivity()).put("WeatherResponse", weatherResponse); setWeatherData(weatherResponse); } } @Override public void onFailure(Call<WeatherResponse> call, Throwable t) { } }); } else { setWeatherData(weatherResponse); } LiveEventBus.get("location", LatLonBean.class).removeObserver(myObserver); } }; /** * 设置天气相关信息 * * @param data */ private void setWeatherData(WeatherResponse data) { try { if (data.getResults() != null) { binding.cityName.setText(data.getResults()[0].getLocation().getName()); binding.time.setText(data.getDate()); int weatherImg = ImageUtils.getWeatherDrawable(data.getResults()[0].getDaily()[0].getCode_day()); if (weatherImg != 0) { binding.weatherImg.setImageDrawable(getResources().getDrawable(weatherImg)); } binding.weatherName.setText(data.getResults()[0].getDaily()[0].getText_day()); binding.weatherTemperature.setText(data.getResults()[0].getDaily()[0].getLow() + "°C ~ " + data.getResults()[0].getDaily()[0].getHigh() + "°C"); } } catch (Exception e) { e.printStackTrace(); CrashReport.postCatchedException(e); } } @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { binding = FragmentMainBinding.inflate(inflater, container, false); //获取到经纬度后获取天气信息 LiveEventBus .get("location", LatLonBean.class) .observeForever(myObserver); return binding.getRoot(); } } app/src/main/java/com/dayu/pipirrapp/fragment/MapFragment.java
@@ -24,6 +24,7 @@ import com.dayu.pipirrapp.js.MyWebViewInterface; import com.dayu.pipirrapp.observer.MapFragmenObserver; import com.dayu.pipirrapp.service.MyLocationService; import com.dayu.pipirrapp.utils.MyLog; import com.dayu.pipirrapp.utils.ToastUtil; import java.util.List; @@ -150,6 +151,7 @@ public void showWaterIntakeDetail(String data){ MyLog.i(data); binding.bottomLL.setVisibility(View.VISIBLE); } app/src/main/java/com/dayu/pipirrapp/fragment/MyFragment.java
@@ -1,5 +1,6 @@ package com.dayu.pipirrapp.fragment; import android.content.Intent; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; @@ -8,8 +9,10 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.dayu.pipirrapp.activity.ChangePSActivity; import com.dayu.pipirrapp.databinding.FragmentMapBinding; import com.dayu.pipirrapp.databinding.FragmentMyBinding; import com.dayu.pipirrapp.view.TitleBar; /** * author: zuo @@ -24,11 +27,20 @@ @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { binding = FragmentMyBinding.inflate(inflater, container, false); initView(); return binding.getRoot(); } private void initView() { new TitleBar(this.getActivity()).setTitleText("我的"); binding.changePS.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MyFragment.this.getContext(), ChangePSActivity.class); MyFragment.this.getActivity().startActivity(intent); } }); } } app/src/main/java/com/dayu/pipirrapp/net/ApiManager.java
@@ -3,6 +3,7 @@ import android.content.Context; import com.dayu.pipirrapp.bean.WeatherResponse; import com.dayu.pipirrapp.net.subscribers.BaseProgressSubscriber; import com.dayu.pipirrapp.net.subscribers.ProgressSubscriber; import com.dayu.pipirrapp.net.subscribers.SubscriberListener; @@ -13,6 +14,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -47,6 +49,9 @@ ApiService apiService; /** * 初始化通信框架 */ public static void init() { if (apiManager == null) { apiManager = new ApiManager(); @@ -152,4 +157,23 @@ } /** * 获取天气 * @param data 经纬度(格式是 纬度:经度,英文冒号分隔) * @param callback * @param <T> */ public <T> void requestWeather(String data,Callback<WeatherResponse> callback) { Map<String, Object> params = new HashMap<>(); params.put("key", "S6Tq4pvOakMuWRrg0"); params.put("location", data); params.put("language", "zh-Hans"); params.put("unit", "c"); params.put("days", "3"); Call<WeatherResponse> call = apiService.requestWeather("https://api.seniverse.com/v3/weather/daily.json", params); call.enqueue(callback); } } app/src/main/java/com/dayu/pipirrapp/net/ApiService.java
@@ -2,7 +2,8 @@ import java.util.List; import com.dayu.pipirrapp.bean.WeatherResponse; import java.util.Map; import io.reactivex.rxjava3.core.Observable; @@ -30,6 +31,11 @@ public interface ApiService { //获取天气 @GET() Call<WeatherResponse> requestWeather(@Url String url, @QueryMap Map<String, Object> params); // @FormUrlEncoded @POST() Observable<BaseResponse> requestPost(@Url String url, @Body Map<String, Object> params); app/src/main/java/com/dayu/pipirrapp/service/MyLocationService.java
@@ -21,7 +21,9 @@ import com.baidu.location.LocationClientOption; import com.dayu.pipirrapp.R; import com.dayu.pipirrapp.activity.MainActivity; import com.dayu.pipirrapp.bean.LatLonBean; import com.dayu.pipirrapp.utils.MyLog; import com.jeremyliao.liveeventbus.LiveEventBus; import com.tencent.bugly.crashreport.CrashReport; /** @@ -41,7 +43,10 @@ /** * 是否一次性定位 */ boolean isSingle; boolean isSingle = false; // 是否已经定位 boolean isPositioned = false; @Nullable @Override @@ -82,16 +87,9 @@ super.onCreate(); createNativeLocation(); // createBDLocation(); createBDLocation(); } // /** // * @param isSingle 是否是单次定位 // */ // public MyLocationService(boolean isSingle) { // this.isSingle = isSingle; // // } /** * 原生的定位服务 @@ -176,6 +174,7 @@ String longitude = "Longitude:" + location.getLongitude(); String latitude = "Latitude:" + location.getLatitude(); MyLog.i("原生定位onLocationChanged: Latitude:" + latitude + " Longitude:" + longitude); postPosition(location.getLatitude(), location.getLongitude()); // 是否一次性定位 if (isSingle) { stopSelf(); // 获取到经纬度以后,停止该service @@ -206,22 +205,42 @@ * 百度定位的监听 */ class MyBDLocationListener extends BDAbstractLocationListener { @Override public void onReceiveLocation(BDLocation location) { double latitude = location.getLatitude(); //获取纬度信息 double longitude = location.getLongitude(); //获取经度信息 // MyLog.i("百度的监听 latitude:" + latitude); // MyLog.i("百度的监听 longitude:" + longitude); MyLog.i("百度的监听 onBaiduLocationChanged: latitude:" + latitude + " longitude:" + longitude); if (isSingle) { stopSelf(); // 获取到经纬度以后,停止该service } } if (!String.valueOf(latitude).equals("4.9E-324")) { //不为4.9E-324时才是定位成功 postPosition(latitude, longitude); if (isSingle) { stopSelf(); // 获取到经纬度以后,停止该service } } } } /** * @param latitude * @param longitude */ private void postPosition(double latitude, double longitude) { if (isSingle && isPositioned) { return; } LatLonBean latLonBean = new LatLonBean(); latLonBean.setLatitude(latitude); latLonBean.setLongitude(longitude); LiveEventBus.get("location").post(latLonBean); } @Override public void onDestroy() { MyLog.i("MyLocationService--onDestroy"); app/src/main/java/com/dayu/pipirrapp/utils/ImageUtils.java
New file @@ -0,0 +1,103 @@ package com.dayu.pipirrapp.utils; import android.graphics.drawable.Drawable; import com.dayu.pipirrapp.R; /** * author: zuo * Date: 2024-01-29 * Time: 15:52 * 备注: */ public class ImageUtils { public static int getWeatherDrawable(String imgName) { switch (imgName) { case "0": return R.mipmap.weather_0; case "1": return R.mipmap.weather_1; case "2": return R.mipmap.weather_2; case "3": return R.mipmap.weather_3; case "4": return R.mipmap.weather_4; case "5": return R.mipmap.weather_5; case "6": return R.mipmap.weather_6; case "7": return R.mipmap.weather_7; case "8": return R.mipmap.weather_8; case "9": return R.mipmap.weather_9; case "10": return R.mipmap.weather_10; case "11": return R.mipmap.weather_11; case "12": return R.mipmap.weather_12; case "13": return R.mipmap.weather_13; case "14": return R.mipmap.weather_14; case "15": return R.mipmap.weather_15; case "16": return R.mipmap.weather_16; case "17": return R.mipmap.weather_17; case "18": return R.mipmap.weather_18; case "19": return R.mipmap.weather_19; case "20": return R.mipmap.weather_20; case "21": return R.mipmap.weather_21; case "22": return R.mipmap.weather_22; case "23": return R.mipmap.weather_23; case "24": return R.mipmap.weather_24; case "25": return R.mipmap.weather_25; case "26": return R.mipmap.weather_26; case "27": return R.mipmap.weather_27; case "28": return R.mipmap.weather_28; case "29": return R.mipmap.weather_29; case "30": return R.mipmap.weather_30; case "31": return R.mipmap.weather_31; case "32": return R.mipmap.weather_32; case "33": return R.mipmap.weather_33; case "34": return R.mipmap.weather_34; case "35": return R.mipmap.weather_35; case "36": return R.mipmap.weather_36; case "37": return R.mipmap.weather_37; case "38": return R.mipmap.weather_38; case "99": return R.mipmap.weather_99; } return 0; } } app/src/main/java/com/dayu/pipirrapp/view/TitleBar.java
@@ -3,14 +3,18 @@ */ package com.dayu.pipirrapp.view; import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Color; import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import com.dayu.pipirrapp.R; @@ -22,248 +26,177 @@ * @author shisl * @time 2015-4-29 */ public class TitleBar extends LinearLayout { public class TitleBar { /** * 左侧/右侧图标和中间标题 */ private View titleView; private static final String TAG = "CNavigationBar"; public static final int LEFT = 0; public static final int CENTER = 1; public static final int RIGHT = 2; public static final int IMAGE = 3; public static final int TEXT = 4; public static final int ClickType_LEFT_TEXT = 1; public static final int ClickType_LEFT_IMAGE = 2; public static final int ClickType_CENTER_TEXT = 3; public static final int ClickType_CENTER_IMAGE = 4; public static final int ClickType_RIGHT_TEXT = 5; public static final int ClickType_RIGHT_IMAGE = 6; /** * 左侧/右侧图标和中间标题 */ private RelativeLayout rl_title_bar; private TextView tvLeft; private ImageView ivLeft; private LinearLayout llLeft; /** * 跟布局 */ private LinearLayout ll_title_bar; private ImageButton ibCenter; private TextView btnCenter; /** * 左侧图标 */ private ImageView iv_left_icon; private TextView tvRight; private ImageView ivRight; private LinearLayout llRight; /** * 右侧图标 */ private ImageView iv_rightIco; /** * 中间标题 */ private TextView tv_title_middle; public TitleBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); initView(context); /** * 右侧标题 */ private TextView tv_title_right; /** * 构造方法:用于获取对象 */ public TitleBar(Activity context) { titleView = context.findViewById(R.id.rl_title_bar); rl_title_bar = (RelativeLayout) titleView.findViewById(R.id.rl_title_bar); ll_title_bar = (LinearLayout) context.findViewById(R.id.ll_title_bar); tv_title_middle = (TextView) titleView.findViewById(R.id.tv_title_middle); tv_title_right = (TextView) titleView.findViewById(R.id.tv_title_right); iv_left_icon = (ImageView) titleView.findViewById(R.id.iv_left_icon); iv_rightIco = (ImageView) titleView.findViewById(R.id.iv_rightIco); } /** * 初始化我们自定义的组合控件 * 用于设置标题栏文字 * * @param titleText 传入要设置的标题 * @return */ private void initView(Context context) { // 转化布局文件————>View对象,这个view对象直接挂载在自己(组合控件)身上 View.inflate(context, R.layout.custom_titlebar, this); // this代表挂载到自己身上 tvLeft = (TextView) this.findViewById(R.id.tv_titlebar_left); btnCenter = (TextView) this.findViewById(R.id.btn_titlebar_center); tvRight = (TextView) this.findViewById(R.id.tv_titlebar_right); ivLeft = (ImageView) this.findViewById(R.id.iv_titlebar_left); ibCenter = (ImageButton) this.findViewById(R.id.ib_titlebar_center); ivRight = (ImageView) this.findViewById(R.id.iv_titlebar_right); llLeft = (LinearLayout) this.findViewById(R.id.ll_left); llRight = (LinearLayout) this.findViewById(R.id.ll_right); } public TitleBar(Context context, AttributeSet attrs) { super(context, attrs); initView(context); try { /** * 跟values/attrs.xml里面定义的属性绑定 */ // 从attrs.xml获取自定义的控件属性 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TitleBar); // //从attrs.xml获取自定义的value属性(控件属性名称+“_” + 自定义的属性名称) String leftText = a.getString(R.styleable.TitleBar_leftText); int leftImage = a.getResourceId(R.styleable.TitleBar_leftImage, 0); String centerText = a.getString(R.styleable.TitleBar_centerText); int centerImage = a.getResourceId(R.styleable.TitleBar_centerImage, 0); String rightText = a.getString(R.styleable.TitleBar_rightText); int rightImage = a.getResourceId(R.styleable.TitleBar_rightImage, 0); a.recycle(); setLeftText(leftText); setRightText(rightText); setCenterText(centerText); setLeftImage(leftImage); setRightImage(rightImage); setCenterImage(centerImage); } catch (Exception e) { e.printStackTrace(); public TitleBar setTitleText(String titleText) { if (!TextUtils.isEmpty(titleText)) { tv_title_middle.setText(titleText); } return this; } @Deprecated public void setOnItemclickListner(int type, int aligh, OnClickListener listner) { if (listner == null) { return; /** * 设置标题栏文字颜色 * * @return */ public TitleBar setTitleTextColor() { tv_title_middle.setTextColor(Color.WHITE); return this; } /** * 设置标题栏右边的文字 * * @return */ public TitleBar setTitleRight(String rightTitle) { if (!TextUtils.isEmpty(rightTitle)) { tv_title_right.setVisibility(View.VISIBLE); iv_rightIco.setVisibility(View.GONE); tv_title_right.setTextColor(Color.WHITE); tv_title_right.setText(rightTitle); } if (type == TEXT) { switch (aligh) { case LEFT: setOnItemclickListner(ClickType_LEFT_TEXT, listner); return this; } break; case CENTER: setOnItemclickListner(ClickType_CENTER_TEXT, listner); break; case RIGHT: setOnItemclickListner(ClickType_RIGHT_TEXT, listner); /** * 用于设置标题栏左边要显示的图片 * * @param resId 标题栏左边的图标的id,一般为返回图标 * @return */ public TitleBar setLeftIco(int resId) { iv_left_icon.setVisibility(resId > 0 ? View.VISIBLE : View.GONE); iv_left_icon.setImageResource(resId); return this; } break; /** * 用于设置标题栏左边要显示的图片 * * @return */ public TitleBar setLeftIco() { iv_left_icon.setVisibility(View.VISIBLE); iv_left_icon.setImageResource(R.drawable.vector_arrows_left_white); return this; } default: break; } } else if (type == IMAGE) { switch (aligh) { case LEFT: setOnItemclickListner(ClickType_LEFT_IMAGE, listner); break; case CENTER: setOnItemclickListner(ClickType_CENTER_IMAGE, listner); /** * 用于设置标题栏右边要显示的图片 * * @param resId 标题栏右边的图标id * @return */ public TitleBar setRightIco(int resId) { iv_rightIco.setVisibility(resId > 0 ? View.VISIBLE : View.GONE); iv_rightIco.setImageResource(resId); return this; } break; case RIGHT: setOnItemclickListner(ClickType_RIGHT_IMAGE, listner); break; /** * 用户设置 标题栏右侧的图标的背景drawable * * @param resId drawable的id * @return */ public TitleBar setRightIconBgDr(int resId) { iv_rightIco.setVisibility(resId > 0 ? View.VISIBLE : View.GONE); // iv_rightIco.setImageResource(R.drawable.ic_back_selector); return this; } default: break; } /** * 用户设置 标题栏右侧的图标的背景drawable * * @return */ public TitleBar setRightIconBgDr() { iv_rightIco.setVisibility(View.GONE); // iv_rightIco.setImageResource(R.drawable.ic_back_selector); return this; } /** * 用于设置标题栏左边图片的单击事件 * * @param listener 传入的事件对象 * @return */ public TitleBar setLeftIcoListening(View.OnClickListener listener) { if (iv_left_icon.getVisibility() == View.VISIBLE) { iv_left_icon.setOnClickListener(listener); } return this; } public void setOnItemclickListner(int clickType, OnClickListener listner) { try { switch (clickType) { case ClickType_LEFT_TEXT: if (tvLeft.getVisibility() == View.VISIBLE) { llLeft.setOnClickListener(listner); } break; case ClickType_LEFT_IMAGE: if (ivLeft.getVisibility() == View.VISIBLE) { llLeft.setOnClickListener(listner); } break; case ClickType_CENTER_TEXT: if (btnCenter.getVisibility() == View.VISIBLE) { btnCenter.setOnClickListener(listner); } break; case ClickType_CENTER_IMAGE: if (ibCenter.getVisibility() == View.VISIBLE) { ibCenter.setOnClickListener(listner); } break; case ClickType_RIGHT_TEXT: if (tvRight.getVisibility() == View.VISIBLE) { llRight.setOnClickListener(listner); } else { llRight.setOnClickListener(null); } break; case ClickType_RIGHT_IMAGE: if (ivRight.getVisibility() == View.VISIBLE) { llRight.setOnClickListener(listner); } break; default: break; } } catch (Exception e) { e.printStackTrace(); /** * 用于设置标题栏右边图片的单击事件 * * @param listener 传入的事件对象 * @return */ public TitleBar setRightIcoListening(View.OnClickListener listener) { if (iv_rightIco.getVisibility() == View.VISIBLE) { iv_rightIco.setOnClickListener(listener); } return this; } public void setLeftImage(int leftImage) { if (leftImage == 0) { ivLeft.setVisibility(View.GONE); return; } ivLeft.setVisibility(View.VISIBLE); ivLeft.setImageResource(leftImage); } public void setRightImage(int rightImage) { if (rightImage == 0) { ivRight.setVisibility(View.GONE); return; } ivRight.setVisibility(View.VISIBLE); ivRight.setImageResource(rightImage); } private void setCenterImage(int leftImage) { if (leftImage == 0) { return; } ivLeft.setBackgroundResource(leftImage); } public void setLeftText(String leftText) { if (leftText == null) { return; } tvLeft.setVisibility(View.VISIBLE); Log.i(TAG, "leftText--->" + leftText); tvLeft.setText(leftText); } public void setRightText(String rightText) { if (rightText == null) { return; } tvRight.setVisibility(View.VISIBLE); llRight.setVisibility(View.VISIBLE); tvRight.setText(rightText); } public void setCenterText(String centerText) { if (centerText == null) { return; } btnCenter.setVisibility(View.VISIBLE); Log.i(TAG, "centerText--->" + centerText); btnCenter.setText(centerText); } public void setRightStatus(boolean isable) { tvRight.setEnabled(isable); ivRight.setEnabled(isable); llRight.setEnabled(isable); } public void setRightIMGVisibility(int Visibility) { ivRight.setVisibility(Visibility); } public TextView getTitleTextView() { return btnCenter; } public LinearLayout getLlRight() { return llRight; } } app/src/main/res/drawable/bg_fillet_blue.xml
New file @@ -0,0 +1,8 @@ <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/base_blue" /> <corners android:radius="5dp" /> <stroke android:width="1dp" android:color="@color/base_blue" /> </shape> app/src/main/res/drawable/vector_arrows_left_white.xml
New file @@ -0,0 +1,16 @@ <?xml version="1.0" encoding="utf-8"?> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="1024" android:viewportHeight="1024"> <path android:fillColor="#FFFFFFFF" android:pathData="M363.841,472.979 C336.939,497.359,337.302,537.486,364.73,561.486 L673.952,832.055 C682.819,839.814,696.296,838.915,704.055,830.048 C711.814,821.181,710.915,807.704,702.048,799.945 L392.827,529.376 C384.596,522.174,384.502,511.835,392.492,504.594 L702.326,223.808 C711.056,215.896,711.72,202.405,703.808,193.674 C695.896,184.944,682.405,184.28,673.674,192.192 L363.841,472.979 Z" /> </vector> app/src/main/res/layout/activity_change_pass_word.xml
@@ -6,12 +6,10 @@ android:background="@color/bg_color" android:orientation="vertical"> <com.dayu.pipirrapp.view.TitleBar <include android:id="@+id/title" android:layout_width="match_parent" android:layout_height="45dp" android:layout_alignParentTop="true" app:centerText="修改密码" /> layout="@layout/top_title" /> <EditText @@ -25,9 +23,12 @@ <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_height="40dp" android:gravity="bottom" android:paddingLeft="20dp" android:paddingBottom="3dp" android:textColor="@color/grey" android:text="密码为6-12位数字或字母" /> <EditText @@ -51,17 +52,14 @@ <TextView android:layout_width="match_parent" android:layout_height="@dimen/item_height" android:background="@drawable/ic_blue_background" android:gravity="center" android:layout_marginRight="40dp" android:layout_marginLeft="40dp" android:layout_marginTop="100dp" android:layout_marginRight="40dp" android:background="@drawable/ic_blue_background" android:gravity="center" android:text="修 改" android:textColor="@color/white" android:textSize="@dimen/common_btn_text_size" /> </LinearLayout> app/src/main/res/layout/fragment_main.xml
@@ -1,6 +1,84 @@ <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> android:layout_height="match_parent" android:background="@color/bg_color"> <include android:id="@+id/title" layout="@layout/top_title" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/title" android:layout_marginStart="10dp" android:layout_marginTop="10dp" android:layout_marginEnd="10dp" android:layout_marginBottom="10dp" android:background="@drawable/bg_fillet_blue" android:paddingLeft="15dp" android:paddingTop="10dp" android:paddingRight="25dp" android:paddingBottom="10dp"> <TextView android:id="@+id/cityName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="城市" android:textColor="@color/white" android:textSize="18sp" /> <TextView android:id="@+id/time" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/cityName" android:layout_alignParentRight="true" android:text="日期" android:textColor="@color/white" android:textSize="16sp" /> <TextView android:id="@+id/weather_name" android:layout_width="wrap_content" android:layout_height="30dp" android:layout_below="@+id/time" android:layout_alignParentRight="true" android:layout_marginTop="10dp" android:gravity="center" android:text="天气" android:textColor="@color/white" android:textSize="16sp" /> <ImageView android:id="@+id/weather_img" android:layout_width="30dp" android:layout_height="30dp" android:layout_alignTop="@+id/weather_name" android:layout_marginRight="10dp" android:layout_toLeftOf="@+id/weather_name" android:src="@mipmap/weather_99" /> <TextView android:id="@+id/weather_temperature" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/weather_name" android:layout_alignParentRight="true" android:layout_marginTop="10dp" android:text="温度" android:textColor="@color/white" android:textSize="16sp" /> </RelativeLayout> </RelativeLayout> app/src/main/res/layout/fragment_my.xml
@@ -6,14 +6,10 @@ android:layout_height="match_parent" android:background="@color/bg_color"> <com.dayu.pipirrapp.view.TitleBar <include android:id="@+id/title" android:layout_width="match_parent" android:layout_height="45dp" android:layout_alignParentTop="true" app:centerText="个人中心" /> layout="@layout/top_title" /> <View @@ -136,6 +132,7 @@ android:layout_marginTop="1dp"> <TextView android:id="@+id/changePS" android:layout_width="match_parent" android:layout_height="@dimen/item_height" app/src/main/res/layout/top_title.xml
New file @@ -0,0 +1,55 @@ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ll_title_bar" android:layout_width="match_parent" android:layout_height="@dimen/title_height" android:background="@color/title_color" android:gravity="center_vertical"> <RelativeLayout android:id="@+id/rl_title_bar" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center_vertical"> <ImageView android:id="@+id/iv_left_icon" android:layout_width="wrap_content" android:layout_height="30dp" android:layout_centerVertical="true" android:layout_marginLeft="5dp" android:scaleType="centerCrop" android:src="@drawable/vector_arrows_left_white" android:visibility="gone" /> <TextView android:id="@+id/tv_title_middle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:textColor="@color/white" android:textSize="@dimen/title_center_text_size" /> <ImageView android:id="@+id/iv_rightIco" android:layout_width="wrap_content" android:layout_height="30dp" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="10dp" android:src="@drawable/vector_loop" android:visibility="gone" /> <TextView android:id="@+id/tv_title_right" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_alignParentRight="true" android:gravity="center_vertical" android:visibility="gone" /> </RelativeLayout> </LinearLayout> app/src/main/res/mipmap-xhdpi/weather_0.png
app/src/main/res/mipmap-xhdpi/weather_1.png
app/src/main/res/mipmap-xhdpi/weather_10.png
app/src/main/res/mipmap-xhdpi/weather_11.png
app/src/main/res/mipmap-xhdpi/weather_12.png
app/src/main/res/mipmap-xhdpi/weather_13.png
app/src/main/res/mipmap-xhdpi/weather_14.png
app/src/main/res/mipmap-xhdpi/weather_15.png
app/src/main/res/mipmap-xhdpi/weather_16.png
app/src/main/res/mipmap-xhdpi/weather_17.png
app/src/main/res/mipmap-xhdpi/weather_18.png
app/src/main/res/mipmap-xhdpi/weather_19.png
app/src/main/res/mipmap-xhdpi/weather_2.png
app/src/main/res/mipmap-xhdpi/weather_20.png
app/src/main/res/mipmap-xhdpi/weather_21.png
app/src/main/res/mipmap-xhdpi/weather_22.png
app/src/main/res/mipmap-xhdpi/weather_23.png
app/src/main/res/mipmap-xhdpi/weather_24.png
app/src/main/res/mipmap-xhdpi/weather_25.png
app/src/main/res/mipmap-xhdpi/weather_26.png
app/src/main/res/mipmap-xhdpi/weather_27.png
app/src/main/res/mipmap-xhdpi/weather_28.png
app/src/main/res/mipmap-xhdpi/weather_29.png
app/src/main/res/mipmap-xhdpi/weather_3.png
app/src/main/res/mipmap-xhdpi/weather_30.png
app/src/main/res/mipmap-xhdpi/weather_31.png
app/src/main/res/mipmap-xhdpi/weather_32.png
app/src/main/res/mipmap-xhdpi/weather_33.png
app/src/main/res/mipmap-xhdpi/weather_34.png
app/src/main/res/mipmap-xhdpi/weather_35.png
app/src/main/res/mipmap-xhdpi/weather_36.png
app/src/main/res/mipmap-xhdpi/weather_37.png
app/src/main/res/mipmap-xhdpi/weather_38.png
app/src/main/res/mipmap-xhdpi/weather_4.png
app/src/main/res/mipmap-xhdpi/weather_5.png
app/src/main/res/mipmap-xhdpi/weather_6.png
app/src/main/res/mipmap-xhdpi/weather_7.png
app/src/main/res/mipmap-xhdpi/weather_8.png
app/src/main/res/mipmap-xhdpi/weather_9.png
app/src/main/res/mipmap-xhdpi/weather_99.png
app/src/main/res/values/dimens.xml
@@ -5,4 +5,5 @@ <dimen name="item_height">50dp</dimen> <dimen name="my_item_text_size">17sp</dimen> <dimen name="common_btn_text_size">20sp</dimen> <dimen name="title_height">45dp</dimen> </resources> app/src/main/res/values/strings.xml
@@ -1,3 +1,3 @@ <resources> <string name="app_name">pipIrrApp</string> <string name="app_name">巡检系统</string> </resources> app/src/main/res/values/styles.xml
@@ -15,13 +15,5 @@ <!-- 标题导航条 --> <declare-styleable name="TitleBar"> <attr name="leftText" format="string" /> <attr name="centerText" format="string" /> <attr name="rightText" format="string" /> <attr name="leftImage" format="integer"></attr> <attr name="centerImage" format="integer"></attr> <attr name="rightImage" format="integer"></attr> </declare-styleable> </resources>