Commit de10ecd9 by chengfengpiaopiao

增加MainActivity

parent 333f1a69
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="EntryPointsManager">
<entry_points version="2.0" />
</component>
<component name="NullableNotNullManager"> <component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" /> <option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" /> <option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
...@@ -55,17 +52,7 @@ ...@@ -55,17 +52,7 @@
</profile-state> </profile-state>
</entry> </entry>
</component> </component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">
......
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/DuoBaoJingCai2.iml" filepath="$PROJECT_DIR$/DuoBaoJingCai2.iml" /> <module fileurl="file://$PROJECT_DIR$/DuoBaoJingCai.iml" filepath="$PROJECT_DIR$/DuoBaoJingCai.iml" />
<module fileurl="file://G:\Product\Android\DuoBaoJingCai\DuoBaoJingCai2.iml" filepath="G:\Product\Android\DuoBaoJingCai\DuoBaoJingCai2.iml" />
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" /> <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
<module fileurl="file://G:\Product\Android\DuoBaoJingCai\app\app.iml" filepath="G:\Product\Android\DuoBaoJingCai\app\app.iml" />
</modules> </modules>
</component> </component>
</project> </project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
...@@ -56,4 +56,6 @@ dependencies { ...@@ -56,4 +56,6 @@ dependencies {
compile "com.squareup.okhttp3:logging-interceptor:$loggingInterceptor" compile "com.squareup.okhttp3:logging-interceptor:$loggingInterceptor"
compile 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:1.0.2' compile 'com.tencent.mm.opensdk:wechat-sdk-android-without-mta:1.0.2'
compile 'cz.msebera.android:httpclient:4.4.1.1' compile 'cz.msebera.android:httpclient:4.4.1.1'
compile 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar'
} }
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
android:label="@string/app_name" android:label="@string/app_name"
android:launchMode="singleTop" android:launchMode="singleTop"
android:screenOrientation="portrait" android:screenOrientation="portrait"
android:theme="@android:style/Theme.NoDisplay" /> android:theme="@android:style/Theme.Translucent.NoTitleBar" />
......
package com.maile.jingcai.module.entity;
import com.flyco.tablayout.listener.CustomTabEntity;
public class TabEntity implements CustomTabEntity {
public String title;
public int selectedIcon;
public int unSelectedIcon;
public TabEntity(String title, int selectedIcon, int unSelectedIcon) {
this.title = title;
this.selectedIcon = selectedIcon;
this.unSelectedIcon = unSelectedIcon;
}
@Override
public String getTabTitle() {
return title;
}
@Override
public int getTabSelectedIcon() {
return selectedIcon;
}
@Override
public int getTabUnselectedIcon() {
return unSelectedIcon;
}
}
package com.maile.jingcai.view;
import android.util.SparseArray;
import android.view.View;
@SuppressWarnings({ "unchecked" })
public class ViewFindUtils
{
/**
* ViewHolder简洁写法,避免适配器中重复定义ViewHolder,减少代码量 用法:
*
* <pre>
* if (convertView == null)
* {
* convertView = View.inflate(context, R.layout.ad_demo, null);
* }
* TextView tv_demo = ViewHolderUtils.get(convertView, R.id.tv_demo);
* ImageView iv_demo = ViewHolderUtils.get(convertView, R.id.iv_demo);
* </pre>
*/
public static <T extends View> T hold(View view, int id)
{
SparseArray<View> viewHolder = (SparseArray<View>) view.getTag();
if (viewHolder == null)
{
viewHolder = new SparseArray<View>();
view.setTag(viewHolder);
}
View childView = viewHolder.get(id);
if (childView == null)
{
childView = view.findViewById(id);
viewHolder.put(id, childView);
}
return (T) childView;
}
/**
* 替代findviewById方法
*/
public static <T extends View> T find(View view, int id)
{
return (T) view.findViewById(id);
}
}
...@@ -3,12 +3,30 @@ package com.maile.jingcai.view.activity; ...@@ -3,12 +3,30 @@ package com.maile.jingcai.view.activity;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import com.flyco.tablayout.CommonTabLayout;
import com.flyco.tablayout.listener.CustomTabEntity;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.flyco.tablayout.utils.UnreadMsgUtils;
import com.flyco.tablayout.widget.MsgView;
import com.maile.jingcai.R; import com.maile.jingcai.R;
import com.maile.jingcai.module.entity.TabEntity;
import com.maile.jingcai.view.ViewFindUtils;
import com.maile.jingcai.view.fragment.SimpleCardFragment;
import java.util.ArrayList;
import java.util.Random;
import butterknife.ButterKnife; import butterknife.ButterKnife;
...@@ -16,7 +34,24 @@ import butterknife.ButterKnife; ...@@ -16,7 +34,24 @@ import butterknife.ButterKnife;
* Created by chengfeng-piaopiao on 2017/11/8. * Created by chengfeng-piaopiao on 2017/11/8.
*/ */
public class MainActivity extends Activity { public class MainActivity extends FragmentActivity {
private Context mContext = this;
private ArrayList<Fragment> mFragments = new ArrayList<>();
private ArrayList<Fragment> mFragments2 = new ArrayList<>();
private String[] mTitles = {"首页", "消息", "联系人", "更多"};
private int[] mIconUnselectIds = {
R.mipmap.tab_home_unselect, R.mipmap.tab_speech_unselect,
R.mipmap.tab_contact_unselect, R.mipmap.tab_more_unselect};
private int[] mIconSelectIds = {
R.mipmap.tab_home_select, R.mipmap.tab_speech_select,
R.mipmap.tab_contact_select, R.mipmap.tab_more_select};
private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();
private View mDecorView;
private ViewPager mViewPager;
private CommonTabLayout mTabLayout_2;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -28,5 +63,114 @@ public class MainActivity extends Activity { ...@@ -28,5 +63,114 @@ public class MainActivity extends Activity {
WindowManager.LayoutParams.FLAG_FULLSCREEN); WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
ButterKnife.inject(this); ButterKnife.inject(this);
for (String title : mTitles) {
mFragments.add(SimpleCardFragment.getInstance("Switch ViewPager " + title));
mFragments2.add(SimpleCardFragment.getInstance("Switch Fragment " + title));
}
for (int i = 0; i < mTitles.length; i++) {
mTabEntities.add(new TabEntity(mTitles[i], mIconSelectIds[i], mIconUnselectIds[i]));
}
mDecorView = getWindow().getDecorView();
mViewPager = ViewFindUtils.find(mDecorView, R.id.vp_2);
mViewPager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
/** with nothing */
/** with ViewPager */
mTabLayout_2 = ViewFindUtils.find(mDecorView, R.id.tl_2);
;
tl_2();
//两位数
mTabLayout_2.showMsg(0, 55);
mTabLayout_2.setMsgMargin(0, -5, 5);
//三位数
mTabLayout_2.showMsg(1, 100);
mTabLayout_2.setMsgMargin(1, -5, 5);
//设置未读消息红点
mTabLayout_2.showDot(2);
MsgView rtv_2_2 = mTabLayout_2.getMsgView(2);
if (rtv_2_2 != null) {
UnreadMsgUtils.setSize(rtv_2_2, dp2px(7.5f));
}
//设置未读消息背景
mTabLayout_2.showMsg(3, 5);
mTabLayout_2.setMsgMargin(3, 0, 5);
MsgView rtv_2_3 = mTabLayout_2.getMsgView(3);
if (rtv_2_3 != null) {
rtv_2_3.setBackgroundColor(Color.parseColor("#6D8FB0"));
}
}
Random mRandom = new Random();
private void tl_2() {
mTabLayout_2.setTabData(mTabEntities);
mTabLayout_2.setOnTabSelectListener(new OnTabSelectListener() {
@Override
public void onTabSelect(int position) {
mViewPager.setCurrentItem(position);
}
@Override
public void onTabReselect(int position) {
if (position == 0) {
mTabLayout_2.showMsg(0, mRandom.nextInt(100) + 1);
// UnreadMsgUtils.show(mTabLayout_2.getMsgView(0), mRandom.nextInt(100) + 1);
}
}
});
mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
mTabLayout_2.setCurrentTab(position);
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
mViewPager.setCurrentItem(1);
}
private class MyPagerAdapter extends FragmentPagerAdapter {
public MyPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return mFragments.size();
}
@Override
public CharSequence getPageTitle(int position) {
return mTitles[position];
}
@Override
public Fragment getItem(int position) {
return mFragments.get(position);
}
}
protected int dp2px(float dp) {
final float scale = mContext.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
} }
} }
package com.maile.jingcai.view.fragment;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.maile.jingcai.R;
@SuppressLint("ValidFragment")
public class SimpleCardFragment extends Fragment {
private String mTitle;
public static SimpleCardFragment getInstance(String title) {
SimpleCardFragment sf = new SimpleCardFragment();
sf.mTitle = title;
return sf;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fr_simple_card, null);
TextView card_title_tv = (TextView) v.findViewById(R.id.card_title_tv);
card_title_tv.setText(mTitle);
return v;
}
}
\ No newline at end of file
...@@ -121,7 +121,7 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler { ...@@ -121,7 +121,7 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
case BaseResp.ErrCode.ERR_USER_CANCEL: case BaseResp.ErrCode.ERR_USER_CANCEL:
Log.i("zou", "<ERR_USER_CANCEL> "); Log.i("zou", "<ERR_USER_CANCEL> ");
// this.finish(); this.finish();
break; break;
case BaseResp.ErrCode.ERR_AUTH_DENIED: case BaseResp.ErrCode.ERR_AUTH_DENIED:
break; break;
...@@ -284,7 +284,6 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler { ...@@ -284,7 +284,6 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
Log.i("tangwen", "<WXEntryActivity> openid= " + openid + Log.i("tangwen", "<WXEntryActivity> openid= " + openid +
" nickname= " + nickname + " headimgurl= " + headimgurl + " mCode =" + mCode + " mAccessToken = " + mAccessToken); " nickname= " + nickname + " headimgurl= " + headimgurl + " mCode =" + mCode + " mAccessToken = " + mAccessToken);
LoginActivity.startEntranceActivity(mContext);
RetrofitManager.getInstance().createReq(LoginApiService.class).thirdLogin(channel,openid,accounType,headimgurl,nickname).subscribeOn(Schedulers.io()) RetrofitManager.getInstance().createReq(LoginApiService.class).thirdLogin(channel,openid,accounType,headimgurl,nickname).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<WrapperRspEntity<String>>() { .subscribe(new Observer<WrapperRspEntity<String>>() {
...@@ -295,6 +294,9 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler { ...@@ -295,6 +294,9 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
@Override @Override
public void onError(Throwable errorException) { public void onError(Throwable errorException) {
LoginActivity.startEntranceActivity(mContext);
mLoading.setVisibility(View.GONE);
finish();
Log.d("tangwen", "onError: " + errorException.getMessage()); Log.d("tangwen", "onError: " + errorException.getMessage());
if (errorException == null) { if (errorException == null) {
PublicUtils.showToast(getString(R.string.error_server_not_ok)); PublicUtils.showToast(getString(R.string.error_server_not_ok));
...@@ -313,11 +315,11 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler { ...@@ -313,11 +315,11 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
if (mIsDestroy) { if (mIsDestroy) {
return; return;
} }
mLoading.setVisibility(View.GONE);
runOnUiThread(new Runnable() { runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
// LoginActivity.startEntranceActivity(mContext); LoginActivity.startEntranceActivity(mContext);
mLoading.setVisibility(View.GONE);
} }
}); });
} }
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:tl="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main" android:id="@+id/activity_main"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin" android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".view.activity.MainActivity"> tools:context=".view.activity.MainActivity">
<TextView <LinearLayout
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent">
android:text="Hello World!" /> <android.support.v4.view.ViewPager
android:id="@+id/vp_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="70dp"
/>
</LinearLayout>
<com.flyco.tablayout.CommonTabLayout
android:id="@+id/tl_2"
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#ffffff"
android:layout_alignParentBottom="true"
tl:tl_iconHeight="23dp"
tl:tl_iconWidth="23dp"
tl:tl_indicator_color="#2C97DE"
tl:tl_indicator_height="0dp"
tl:tl_textSelectColor="#2C97DE"
tl:tl_textUnselectColor="#66000000"
tl:tl_textsize="12sp"
tl:tl_underline_color="#DDDDDD"
tl:tl_underline_height="1dp"/>
</RelativeLayout> </RelativeLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/card_title_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:background="@drawable/background_card"
android:gravity="center"
android:textSize="18sp"/>
</RelativeLayout>
\ No newline at end of file
...@@ -5,7 +5,7 @@ buildscript { ...@@ -5,7 +5,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:2.2.3' classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files
......
...@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME ...@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment