Commit c77a0d75bbdc73c92506d6b907b074690b579ad2

Authored by 陈硕
1 parent 01c7920a

修改页面布局

app/src/main/java/com/cnlive/gundam/main/ui/fragment/ConfigFragment.java
@@ -9,12 +9,14 @@ import android.view.LayoutInflater; @@ -9,12 +9,14 @@ import android.view.LayoutInflater;
9 import android.view.View; 9 import android.view.View;
10 import android.view.ViewGroup; 10 import android.view.ViewGroup;
11 11
  12 +import com.bumptech.glide.Glide;
12 import com.cnlive.gundam.R; 13 import com.cnlive.gundam.R;
13 import com.cnlive.gundam.databinding.UserFragmentBinding; 14 import com.cnlive.gundam.databinding.UserFragmentBinding;
14 import com.cnlive.gundam.user.activity.CommentActivity; 15 import com.cnlive.gundam.user.activity.CommentActivity;
15 import com.cnlive.gundam.user.activity.LoginActivity; 16 import com.cnlive.gundam.user.activity.LoginActivity;
  17 +import com.cnlive.gundam.user.activity.UserPersonalActivity;
16 import com.cnlive.gundam.user.auth.UserService; 18 import com.cnlive.gundam.user.auth.UserService;
17 - 19 +import com.cnlive.gundam.user.model.User;
18 20
19 21
20 /** 22 /**
@@ -28,7 +30,6 @@ public class ConfigFragment extends Fragment implements View.OnClickListener { @@ -28,7 +30,6 @@ public class ConfigFragment extends Fragment implements View.OnClickListener {
28 @Override 30 @Override
29 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 31 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
30 binding = DataBindingUtil.inflate(inflater, R.layout.user_fragment, container, false); 32 binding = DataBindingUtil.inflate(inflater, R.layout.user_fragment, container, false);
31 -  
32 return binding.getRoot(); 33 return binding.getRoot();
33 } 34 }
34 35
@@ -39,24 +40,14 @@ public class ConfigFragment extends Fragment implements View.OnClickListener { @@ -39,24 +40,14 @@ public class ConfigFragment extends Fragment implements View.OnClickListener {
39 } 40 }
40 41
41 42
42 - /* public static Fragment newInstance() {  
43 - UserFragment fragment = new UserFragment();  
44 - return fragment;  
45 - }*/  
46 -  
47 @Override 43 @Override
48 public void onActivityCreated(Bundle savedInstanceState) { 44 public void onActivityCreated(Bundle savedInstanceState) {
49 super.onActivityCreated(savedInstanceState); 45 super.onActivityCreated(savedInstanceState);
50 46
51 -  
52 - /*initToolBar();  
53 - init();  
54 - MyHeadItem.getContent(getActivity());*/  
55 } 47 }
56 48
57 private void initUI() { 49 private void initUI() {
58 binding.configHeader.setOnClickListener(this); 50 binding.configHeader.setOnClickListener(this);
59 - binding.live.setOnClickListener(this);  
60 binding.message.setOnClickListener(this); 51 binding.message.setOnClickListener(this);
61 } 52 }
62 53
@@ -64,28 +55,32 @@ public class ConfigFragment extends Fragment implements View.OnClickListener { @@ -64,28 +55,32 @@ public class ConfigFragment extends Fragment implements View.OnClickListener {
64 @Override 55 @Override
65 public void onClick(View view) { 56 public void onClick(View view) {
66 switch (view.getId()) { 57 switch (view.getId()) {
67 -  
68 -  
69 case R.id.config_header: 58 case R.id.config_header:
70 int uid = UserService.getInstance(getActivity()).getActiveAccountInfo().getUid(); 59 int uid = UserService.getInstance(getActivity()).getActiveAccountInfo().getUid();
71 - if (uid != 0) {  
72 - //进入个人中心页面  
73 - //startActivity(new Intent(getActivity(), UserPersonalActivity.class));  
74 - } else {  
75 - //进入登录页面 60 + if (uid != 0)
  61 + startActivity(new Intent(getActivity(), UserPersonalActivity.class));
  62 + else
76 startActivity(new Intent(getActivity(), LoginActivity.class)); 63 startActivity(new Intent(getActivity(), LoginActivity.class));
77 - }  
78 -  
79 break; 64 break;
80 - case R.id.live:  
81 65
82 - break;  
83 case R.id.message: 66 case R.id.message:
84 startActivity(new Intent(getActivity(), CommentActivity.class)); 67 startActivity(new Intent(getActivity(), CommentActivity.class));
85 -  
86 break; 68 break;
87 69
88 } 70 }
89 71
90 } 72 }
  73 +
  74 + @Override
  75 + public void onResume() {
  76 + super.onResume();
  77 + notifyUI();
  78 +
  79 + }
  80 +
  81 + private void notifyUI() {
  82 + User activeAccountInfo = UserService.getInstance(getActivity()).getActiveAccountInfo();
  83 + Glide.with(getActivity()).load(activeAccountInfo.getFaceurl()).into(binding.headImg);
  84 + binding.tvNickname.setText(activeAccountInfo.getNickname());
  85 + }
91 } 86 }
app/src/main/java/com/cnlive/gundam/user/fragment/FeedbackFragment.java
@@ -67,7 +67,7 @@ public class FeedbackFragment extends Fragment implements View.OnClickListener { @@ -67,7 +67,7 @@ public class FeedbackFragment extends Fragment implements View.OnClickListener {
67 public void onClick(View v) { 67 public void onClick(View v) {
68 int i = v.getId(); 68 int i = v.getId();
69 if (i == R.id.back_selector) {//返回上一页面 69 if (i == R.id.back_selector) {//返回上一页面
70 - getFragmentManager().popBackStack(); 70 + getActivity().finish();
71 71
72 } else if (i == R.id.feedback) { 72 } else if (i == R.id.feedback) {
73 /** 73 /**
@@ -94,7 +94,7 @@ public class FeedbackFragment extends Fragment implements View.OnClickListener { @@ -94,7 +94,7 @@ public class FeedbackFragment extends Fragment implements View.OnClickListener {
94 switch (what) { 94 switch (what) {
95 case IUserService.SUCCESS: 95 case IUserService.SUCCESS:
96 ToastUtil.show(getActivity(), "反馈成功"); 96 ToastUtil.show(getActivity(), "反馈成功");
97 - getFragmentManager().popBackStack(); 97 + getActivity().finish();
98 break; 98 break;
99 case IUserService.ERROR_PARAM: 99 case IUserService.ERROR_PARAM:
100 ToastUtil.show(getActivity(), IUserService.message_error_param); 100 ToastUtil.show(getActivity(), IUserService.message_error_param);
app/src/main/java/com/cnlive/gundam/user/fragment/LoginFragment.java
@@ -155,6 +155,7 @@ public class LoginFragment extends Fragment implements View.OnClickListener { @@ -155,6 +155,7 @@ public class LoginFragment extends Fragment implements View.OnClickListener {
155 closeDialog(); 155 closeDialog();
156 UserData userData = (UserData) obj; 156 UserData userData = (UserData) obj;
157 data = userData.getData(); 157 data = userData.getData();
  158 +
158 UserService userService = UserService.getInstance(getActivity()); 159 UserService userService = UserService.getInstance(getActivity());
159 userService.setUserInfo(account, data); 160 userService.setUserInfo(account, data);
160 //userService.isAutoLogin(); 161 //userService.isAutoLogin();
app/src/main/java/com/cnlive/gundam/user/fragment/UserPersonalFragment.java
@@ -49,4 +49,7 @@ public class UserPersonalFragment extends Fragment{ @@ -49,4 +49,7 @@ public class UserPersonalFragment extends Fragment{
49 49
50 50
51 51
  52 +
  53 +
  54 +
52 } 55 }
app/src/main/java/com/cnlive/gundam/user/view/CircleImageView.java 0 → 100644
  1 +package com.cnlive.gundam.user.view;
  2 +
  3 +import android.annotation.SuppressLint;
  4 +import android.content.Context;
  5 +import android.content.res.TypedArray;
  6 +import android.graphics.Bitmap;
  7 +import android.graphics.BitmapShader;
  8 +import android.graphics.Canvas;
  9 +import android.graphics.Color;
  10 +import android.graphics.Matrix;
  11 +import android.graphics.Paint;
  12 +import android.graphics.RectF;
  13 +import android.graphics.Shader;
  14 +import android.graphics.drawable.BitmapDrawable;
  15 +import android.graphics.drawable.ColorDrawable;
  16 +import android.graphics.drawable.Drawable;
  17 +import android.util.AttributeSet;
  18 +import android.widget.ImageView;
  19 +
  20 +import com.cnlive.gundam.R;
  21 +
  22 +
  23 +/**
  24 + * @author 陈硕
  25 + * @time 2016/11/7 10:27
  26 + * @desc ${TODD}
  27 + */
  28 +@SuppressLint("AppCompatCustomView")
  29 +public class CircleImageView extends ImageView {
  30 +
  31 +
  32 + private static final ImageView.ScaleType SCALE_TYPE = ImageView.ScaleType.CENTER_CROP;
  33 +
  34 + private static final Bitmap.Config BITMAP_CONFIG = Bitmap.Config.ARGB_8888;
  35 + private static final int COLORDRAWABLE_DIMENSION = 1;
  36 +
  37 + private static final int DEFAULT_BORDER_WIDTH = 0;
  38 + private static final int DEFAULT_BORDER_COLOR = Color.BLACK;
  39 +
  40 + private final RectF mDrawableRect = new RectF();
  41 + private final RectF mBorderRect = new RectF();
  42 +
  43 + private final Matrix mShaderMatrix = new Matrix();
  44 + private final Paint mBitmapPaint = new Paint();
  45 + private final Paint mBorderPaint = new Paint();
  46 +
  47 + private int mBorderColor = DEFAULT_BORDER_COLOR;
  48 + private int mBorderWidth = DEFAULT_BORDER_WIDTH;
  49 +
  50 + private Bitmap mBitmap;
  51 + private BitmapShader mBitmapShader;
  52 + private int mBitmapWidth;
  53 + private int mBitmapHeight;
  54 +
  55 + private float mDrawableRadius;
  56 + private float mBorderRadius;
  57 +
  58 + private boolean mReady;
  59 + private boolean mSetupPending;
  60 +
  61 + public CircleImageView(Context context) {
  62 + super(context);
  63 + }
  64 +
  65 + public CircleImageView(Context context, AttributeSet attrs) {
  66 + this(context, attrs, 0);
  67 + }
  68 +
  69 + public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
  70 + super(context, attrs, defStyle);
  71 + super.setScaleType(SCALE_TYPE);
  72 +
  73 + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0);
  74 +
  75 + mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_border_width, DEFAULT_BORDER_WIDTH);
  76 + mBorderColor = a.getColor(R.styleable.CircleImageView_border_color, DEFAULT_BORDER_COLOR);
  77 +
  78 + a.recycle();
  79 +
  80 + mReady = true;
  81 +
  82 + if (mSetupPending) {
  83 + setup();
  84 + mSetupPending = false;
  85 + }
  86 + }
  87 +
  88 + @Override
  89 + public ScaleType getScaleType() {
  90 + return SCALE_TYPE;
  91 + }
  92 +
  93 + @Override
  94 + public void setScaleType(ScaleType scaleType) {
  95 + if (scaleType != SCALE_TYPE) {
  96 + throw new IllegalArgumentException(String.format("ScaleType %s not supported.", scaleType));
  97 + }
  98 + }
  99 +
  100 + @Override
  101 + protected void onDraw(Canvas canvas) {
  102 + if (getDrawable() == null) {
  103 + return;
  104 + }
  105 +
  106 + canvas.drawCircle(getWidth() / 2, getHeight() / 2, mDrawableRadius, mBitmapPaint);
  107 + canvas.drawCircle(getWidth() / 2, getHeight() / 2, mBorderRadius, mBorderPaint);
  108 + }
  109 +
  110 + @Override
  111 + protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  112 + super.onSizeChanged(w, h, oldw, oldh);
  113 + setup();
  114 + }
  115 +
  116 + public int getBorderColor() {
  117 + return mBorderColor;
  118 + }
  119 +
  120 + public void setBorderColor(int borderColor) {
  121 + if (borderColor == mBorderColor) {
  122 + return;
  123 + }
  124 +
  125 + mBorderColor = borderColor;
  126 + mBorderPaint.setColor(mBorderColor);
  127 + invalidate();
  128 + }
  129 +
  130 + public int getBorderWidth() {
  131 + return mBorderWidth;
  132 + }
  133 +
  134 + public void setBorderWidth(int borderWidth) {
  135 + if (borderWidth == mBorderWidth) {
  136 + return;
  137 + }
  138 +
  139 + mBorderWidth = borderWidth;
  140 + setup();
  141 + }
  142 +
  143 + @Override
  144 + public void setImageBitmap(Bitmap bm) {
  145 + super.setImageBitmap(bm);
  146 + mBitmap = bm;
  147 + setup();
  148 + }
  149 +
  150 + @Override
  151 + public void setImageDrawable(Drawable drawable) {
  152 + super.setImageDrawable(drawable);
  153 + mBitmap = getBitmapFromDrawable(drawable);
  154 + setup();
  155 + }
  156 +
  157 + @Override
  158 + public void setImageResource(int resId) {
  159 + super.setImageResource(resId);
  160 + mBitmap = getBitmapFromDrawable(getDrawable());
  161 + setup();
  162 + }
  163 +
  164 + private Bitmap getBitmapFromDrawable(Drawable drawable) {
  165 + if (drawable == null) {
  166 + return null;
  167 + }
  168 +
  169 + if (drawable instanceof BitmapDrawable) {
  170 + return ((BitmapDrawable) drawable).getBitmap();
  171 + }
  172 +
  173 + try {
  174 + Bitmap bitmap;
  175 +
  176 + if (drawable instanceof ColorDrawable) {
  177 + bitmap = Bitmap.createBitmap(COLORDRAWABLE_DIMENSION, COLORDRAWABLE_DIMENSION, BITMAP_CONFIG);
  178 + } else {
  179 + bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), BITMAP_CONFIG);
  180 + }
  181 +
  182 + Canvas canvas = new Canvas(bitmap);
  183 + drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
  184 + drawable.draw(canvas);
  185 + return bitmap;
  186 + } catch (OutOfMemoryError e) {
  187 + return null;
  188 + }
  189 + }
  190 +
  191 + private void setup() {
  192 + if (!mReady) {
  193 + mSetupPending = true;
  194 + return;
  195 + }
  196 +
  197 + if (mBitmap == null) {
  198 + return;
  199 + }
  200 +
  201 + mBitmapShader = new BitmapShader(mBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
  202 +
  203 + mBitmapPaint.setAntiAlias(true);
  204 + mBitmapPaint.setShader(mBitmapShader);
  205 +
  206 + mBorderPaint.setStyle(Paint.Style.STROKE);
  207 + mBorderPaint.setAntiAlias(true);
  208 + mBorderPaint.setColor(mBorderColor);
  209 + mBorderPaint.setStrokeWidth(mBorderWidth);
  210 +
  211 + mBitmapHeight = mBitmap.getHeight();
  212 + mBitmapWidth = mBitmap.getWidth();
  213 +
  214 + mBorderRect.set(0, 0, getWidth(), getHeight());
  215 + mBorderRadius = Math.min((mBorderRect.height() - mBorderWidth) / 2, (mBorderRect.width() - mBorderWidth) / 2);
  216 +
  217 + mDrawableRect.set(mBorderWidth, mBorderWidth, mBorderRect.width() - mBorderWidth, mBorderRect.height() - mBorderWidth);
  218 + mDrawableRadius = Math.min(mDrawableRect.height() / 2, mDrawableRect.width() / 2);
  219 +
  220 + updateShaderMatrix();
  221 + invalidate();
  222 + }
  223 +
  224 + private void updateShaderMatrix() {
  225 + float scale;
  226 + float dx = 0;
  227 + float dy = 0;
  228 +
  229 + mShaderMatrix.set(null);
  230 +
  231 + if (mBitmapWidth * mDrawableRect.height() > mDrawableRect.width() * mBitmapHeight) {
  232 + scale = mDrawableRect.height() / (float) mBitmapHeight;
  233 + dx = (mDrawableRect.width() - mBitmapWidth * scale) * 0.5f;
  234 + } else {
  235 + scale = mDrawableRect.width() / (float) mBitmapWidth;
  236 + dy = (mDrawableRect.height() - mBitmapHeight * scale) * 0.5f;
  237 + }
  238 +
  239 + mShaderMatrix.setScale(scale, scale);
  240 + mShaderMatrix.postTranslate((int) (dx + 0.5f) + mBorderWidth, (int) (dy + 0.5f) + mBorderWidth);
  241 +
  242 + mBitmapShader.setLocalMatrix(mShaderMatrix);
  243 + }
  244 +
  245 +}
  246 +
  247 +
app/src/main/res/layout/user_feedback.xml
@@ -25,6 +25,8 @@ @@ -25,6 +25,8 @@
25 android:id="@+id/feedback_textView" 25 android:id="@+id/feedback_textView"
26 android:layout_width="match_parent" 26 android:layout_width="match_parent"
27 android:layout_height="wrap_content" 27 android:layout_height="wrap_content"
  28 + android:paddingTop="@dimen/_20px"
  29 + android:paddingBottom="@dimen/_20px"
28 android:layout_centerVertical="true" 30 android:layout_centerVertical="true"
29 android:layout_marginLeft="@dimen/_30px" 31 android:layout_marginLeft="@dimen/_30px"
30 android:background="@null" 32 android:background="@null"
app/src/main/res/layout/user_fragment.xml
@@ -10,20 +10,23 @@ @@ -10,20 +10,23 @@
10 10
11 <RelativeLayout 11 <RelativeLayout
12 android:layout_width="match_parent" 12 android:layout_width="match_parent"
13 - android:layout_height="100dp" 13 + android:layout_height="150dp"
14 > 14 >
15 <TextView 15 <TextView
16 android:layout_width="wrap_content" 16 android:layout_width="wrap_content"
17 android:layout_height="wrap_content" 17 android:layout_height="wrap_content"
18 android:layout_centerInParent="true" 18 android:layout_centerInParent="true"
  19 + android:singleLine="true"
19 android:text="我的" 20 android:text="我的"
20 - android:textSize="@dimen/_30px" 21 + android:textColor="@color/config_black_color"
  22 + android:textSize="22sp"
21 /> 23 />
22 24
23 25
24 </RelativeLayout> 26 </RelativeLayout>
25 <View 27 <View
26 android:layout_width="match_parent" 28 android:layout_width="match_parent"
  29 + android:layout_marginBottom="@dimen/_20px"
27 android:layout_height="1px" 30 android:layout_height="1px"
28 android:background="@color/gray_line_color" /> 31 android:background="@color/gray_line_color" />
29 32
@@ -35,11 +38,12 @@ @@ -35,11 +38,12 @@
35 android:gravity="center_vertical" 38 android:gravity="center_vertical"
36 style="@style/list_item_style"> 39 style="@style/list_item_style">
37 40
38 - <ImageView 41 + <com.cnlive.gundam.user.view.CircleImageView
39 android:id="@+id/head_img" 42 android:id="@+id/head_img"
40 android:layout_width="55dip" 43 android:layout_width="55dip"
41 android:layout_height="55dip" 44 android:layout_height="55dip"
42 android:layout_centerVertical="true" 45 android:layout_centerVertical="true"
  46 + android:src="@drawable/cnlive_user_header"
43 android:layout_marginLeft="11dp" 47 android:layout_marginLeft="11dp"
44 android:layout_marginRight="16dp" /> 48 android:layout_marginRight="16dp" />
45 49
@@ -61,14 +65,7 @@ @@ -61,14 +65,7 @@
61 android:text="@string/click_login" 65 android:text="@string/click_login"
62 android:textColor="@color/config_black_color" 66 android:textColor="@color/config_black_color"
63 android:textSize="17sp" /> 67 android:textSize="17sp" />
64 - <TextView  
65 - android:id="@+id/point"  
66 - android:layout_width="wrap_content"  
67 - android:layout_height="wrap_content"  
68 - android:layout_margin="3dp"  
69 - android:text="@string/login_china_coin"  
70 - android:textColor="@color/config_gray_color"  
71 - android:textSize="12sp" /> 68 +
72 </LinearLayout> 69 </LinearLayout>
73 70
74 <ImageView 71 <ImageView
@@ -86,38 +83,21 @@ @@ -86,38 +83,21 @@
86 83
87 84
88 85
89 - <RelativeLayout  
90 - android:layout_width="match_parent"  
91 - android:layout_height="30dp"  
92 - android:id="@+id/live"  
93 - style="@style/list_item_style">  
94 - <ImageView  
95 - android:layout_width="20dp"  
96 - android:layout_height="20dp"  
97 - android:id="@+id/ic_config_history"  
98 - android:layout_centerVertical="true"  
99 - android:src="@drawable/ic_config_history"/>  
100 - <TextView  
101 - android:layout_width="wrap_content"  
102 - android:layout_height="wrap_content"  
103 - android:layout_centerVertical="true"  
104 - android:layout_toRightOf="@+id/ic_config_history"  
105 - android:layout_marginLeft="20dp"  
106 - android:text="我要直播"/>  
107 - </RelativeLayout>  
108 <View 86 <View
109 android:layout_width="match_parent" 87 android:layout_width="match_parent"
110 android:layout_height="1px" 88 android:layout_height="1px"
111 android:background="@color/gray_line_color" /> 89 android:background="@color/gray_line_color" />
112 <RelativeLayout 90 <RelativeLayout
113 android:layout_width="match_parent" 91 android:layout_width="match_parent"
114 - android:layout_height="30dp" 92 + android:layout_height="50dp"
  93 + android:layout_marginTop="@dimen/_20px"
115 android:id="@+id/message" 94 android:id="@+id/message"
116 style="@style/list_item_style"> 95 style="@style/list_item_style">
117 96
118 <ImageView 97 <ImageView
119 - android:layout_width="20dp"  
120 - android:layout_height="20dp" 98 + android:layout_width="30dp"
  99 + android:layout_height="30dp"
  100 + android:layout_marginLeft="@dimen/_20px"
121 android:layout_centerVertical="true" 101 android:layout_centerVertical="true"
122 android:id="@+id/ic_setting_opinion" 102 android:id="@+id/ic_setting_opinion"
123 android:src="@drawable/ic_setting_opinion"/> 103 android:src="@drawable/ic_setting_opinion"/>
@@ -126,8 +106,23 @@ @@ -126,8 +106,23 @@
126 android:layout_height="wrap_content" 106 android:layout_height="wrap_content"
127 android:layout_centerVertical="true" 107 android:layout_centerVertical="true"
128 android:layout_toRightOf="@+id/ic_setting_opinion" 108 android:layout_toRightOf="@+id/ic_setting_opinion"
129 - android:layout_marginLeft="20dp"  
130 - android:text="意见反馈"/> 109 + android:gravity="center_vertical"
  110 + android:singleLine="true"
  111 + android:text="意见反馈"
  112 + android:textColor="@color/config_black_color"
  113 + android:layout_marginLeft="30dp"
  114 + android:textSize="17sp"/>
  115 +
  116 +
  117 + <ImageView
  118 + android:id="@+id/imv_message"
  119 + android:layout_width="@dimen/next_image_width"
  120 + android:layout_height="@dimen/next_image_height"
  121 + android:layout_alignParentRight="true"
  122 + android:layout_centerVertical="true"
  123 + android:layout_marginRight="@dimen/next_image_margin_right"
  124 + android:contentDescription="@null"
  125 + android:src="@drawable/btn_channel_more" />
131 126
132 </RelativeLayout> 127 </RelativeLayout>
133 128
user/src/main/res/values/attrs.xml 0 → 100644
  1 +<?xml version="1.0" encoding="utf-8"?>
  2 +<resources>
  3 + <declare-styleable name="CircleImageView">
  4 + <attr name="border_width" format="dimension" />
  5 + <attr name="border_color" format="color" />
  6 + </declare-styleable>
  7 +</resources>
0 \ No newline at end of file 8 \ No newline at end of file