diff --git a/app/build.gradle b/app/build.gradle index afcaad3812..e566ada4bf 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,7 +29,7 @@ android { versionName rootProject.ext.versionName applicationId rootProject.ext.applicationId - multiDexEnabled = true; + multiDexEnabled true } @@ -103,6 +103,7 @@ dependencies { compile libs.supportRecyclerView compile libs.supportAppCompat compile libs.supportAnnotation + compile libs.supportPercent compile libs.switchButton diff --git a/app/src/main/java/com/gh/base/NewBaseActivity.java b/app/src/main/java/com/gh/base/NewBaseActivity.java new file mode 100644 index 0000000000..b0b5cff3e6 --- /dev/null +++ b/app/src/main/java/com/gh/base/NewBaseActivity.java @@ -0,0 +1,242 @@ +package com.gh.base; + +import android.annotation.TargetApi; +import android.content.Context; +import android.graphics.Color; +import android.os.Build; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.view.*; +import android.view.View.OnClickListener; +import android.view.ViewGroup.LayoutParams; +import android.widget.*; +import butterknife.ButterKnife; +import com.gh.common.constant.Config; +import com.gh.common.util.*; +import com.gh.download.DownloadManager; +import com.gh.gamecenter.R; +import com.gh.gamecenter.eventbus.EBShowDialog; +import com.gh.gamecenter.listener.OnCallBackListener; +import com.readystatesoftware.systembartint.SystemBarTintManager; +import com.readystatesoftware.systembartint.SystemBarTintManager.SystemBarConfig; +import de.greenrobot.event.EventBus; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; + +import static com.gh.common.util.EntranceUtils.KEY_DATA; +import static com.gh.common.util.EntranceUtils.KEY_ENTRANCE; + +public class NewBaseActivity extends AppCompatActivity implements OnCallBackListener { + + protected String entrance; + private SystemBarTintManager mTintManager; + private boolean isPause; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + Utils.log(this.getClass().getSimpleName()); + AppController.getInstance().addActivity(this); + EventBus.getDefault().register(this); + entrance = getIntent().getStringExtra(KEY_ENTRANCE); + if (getIntent().getBundleExtra(KEY_DATA) != null) { + entrance = getIntent().getBundleExtra(KEY_DATA).getString(KEY_ENTRANCE); + } + } + + protected void init(View contentView, String title) { + init(contentView); + TextView actionbar_tv_title = (TextView) findViewById(R.id.actionbar_tv_title); + actionbar_tv_title.setText(title); + } + + protected void init(View contentView) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + setTheme(R.style.AppCompatTheme); + setTranslucentStatus(true); + mTintManager = new SystemBarTintManager(this); + mTintManager.setStatusBarTintEnabled(true); +// mTintManager.setNavigationBarTintEnabled(true); + if (Build.MANUFACTURER.equals("Meizu") || Build.MANUFACTURER.equals("Xiaomi")) { + mTintManager.setStatusBarTintColor(Color.WHITE); + } else { + mTintManager.setStatusBarTintColor(Color.BLACK); + } + SystemBarConfig config = mTintManager.getConfig(); + contentView.setPadding(0, config.getPixelInsetTop(false), 0, + config.getPixelInsetBottom()); + + if (Build.MANUFACTURER.equals("Meizu")) { + try { + Window window = getWindow(); + if (window != null) { + WindowManager.LayoutParams lp = window.getAttributes(); + Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON"); + Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags"); + darkFlag.setAccessible(true); + meizuFlags.setAccessible(true); + int bit = darkFlag.getInt(null); + int value = meizuFlags.getInt(lp); + value |= bit; + meizuFlags.setInt(lp, value); + window.setAttributes(lp); + } + } catch (Exception e) { + e.printStackTrace(); + } + } else if (Build.MANUFACTURER.equals("Xiaomi")) { + try { + Window window = getWindow(); + if (window != null) { + Class clazz = window.getClass(); + Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams"); + Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE"); + int darkModeFlag = field.getInt(layoutParams); + Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class); + extraFlagField.invoke(window, darkModeFlag, darkModeFlag); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + setContentView(contentView); + + ButterKnife.bind(this); + + int actionbar_height = getSharedPreferences(Config.PREFERENCE, + Context.MODE_PRIVATE).getInt("actionbar_height", + DisplayUtils.dip2px(getApplicationContext(), 55)); + + RelativeLayout reuse_actionbar = (RelativeLayout) findViewById(R.id.reuse_actionbar); + LinearLayout.LayoutParams lparams = new LinearLayout.LayoutParams( + LayoutParams.MATCH_PARENT, actionbar_height); + reuse_actionbar.setLayoutParams(lparams); + + findViewById(R.id.actionbar_rl_back).setOnClickListener( + new OnClickListener() { + @Override + public void onClick(View v) { + finish(); + } + }); + } + + protected SystemBarTintManager getTintManager() { + return mTintManager; + } + + @Override + public void finish() { + super.finish(); + AppController.getInstance().removeActivity(this); + } + + public void toast(String msg) { + Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); + } + + public void toast(int msg) { + Toast.makeText(this, msg, Toast.LENGTH_SHORT).show(); + } + + @TargetApi(19) + protected void setTranslucentStatus(boolean status) { + Window window = getWindow(); + WindowManager.LayoutParams winParams = window.getAttributes(); + final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; + if (status) { + winParams.flags |= bits; + } else { + winParams.flags &= ~bits; + } + window.setAttributes(winParams); + } + + //如果是游戏分享,newsTitle默认为空 + public void showShare(String url, String gameName, String icon, String newsTitle, ArrayList tag) { + + //判断是否是官方版 + boolean isPlugin = false; + if (tag != null) { + for (String s : tag) { + if (!"官方版".equals(s)) { + isPlugin = true; + } + } + } + + ShareUtils.getInstance(this).showShareWindows(new View(this), url, gameName, icon, newsTitle, isPlugin, true); + + if (newsTitle == null) { + DataUtils.onEvent(this, "内容分享", gameName); + } else { + DataUtils.onEvent(this, "内容分享", newsTitle); + } + } + + + public void onEventMainThread(final EBShowDialog showDialog) { + if (!isPause && this.getClass().getName().equals(RunningUtils.getTopActivity(this))) { + if ("hijack".equals(showDialog.getType())) { + DialogUtils.showQqSessionDialog(this, null);// 建议用户联系客服 + } else if ("plugin".equals(showDialog.getType())) { + DialogUtils.showPluginDialog(this, new DialogUtils.ConfirmListener() { + @Override + public void onConfirm() { + if (FileUtils.isEmptyFile(showDialog.getPath())) { + Toast.makeText(NewBaseActivity.this, "解析包出错(可能被误删了),请重新下载", Toast.LENGTH_SHORT).show(); + } else { + startActivity(PackageUtils.getUninstallIntent(NewBaseActivity.this, showDialog.getPath())); + } + } + }); + } + } + } + + @Override + protected void onDestroy() { + super.onDestroy(); + EventBus.getDefault().unregister(this); + } + + @Override + protected void onPause() { + super.onPause(); + DataUtils.onPause(this); + isPause = true; + } + + @Override + protected void onResume() { + super.onResume(); + DataUtils.onResume(this); + isPause = false; + DownloadManager.getInstance(this).initGameMap(); + } + + @Override + public void loadDone() { + + } + + @Override + public void loadDone(Object obj) { + + } + + @Override + public void loadError() { + + } + + @Override + public void loadEmpty() { + + } + +} diff --git a/app/src/main/java/com/gh/base/OnBackPressedListener.java b/app/src/main/java/com/gh/base/OnBackPressedListener.java new file mode 100644 index 0000000000..d35f542f4b --- /dev/null +++ b/app/src/main/java/com/gh/base/OnBackPressedListener.java @@ -0,0 +1,10 @@ +package com.gh.base; + +/** + * @author CsHeng + * @Date 2017/4/28 + * @Time 18:59 + */ +public interface OnBackPressedListener { + void onActionbarBackPressed(); +} diff --git a/app/src/main/java/com/gh/gamecenter/AboutActivity.java b/app/src/main/java/com/gh/gamecenter/AboutActivity.java index a7d3f4cc21..bade6d10df 100644 --- a/app/src/main/java/com/gh/gamecenter/AboutActivity.java +++ b/app/src/main/java/com/gh/gamecenter/AboutActivity.java @@ -11,6 +11,8 @@ import com.gh.base.BaseActivity; import com.gh.common.util.PackageUtils; import com.gh.gamecenter.manager.UpdateManager; +import java.lang.ref.WeakReference; + /** * Created by khy on 2017/2/28. */ @@ -21,20 +23,32 @@ public class AboutActivity extends BaseActivity { @BindView(R.id.about_version_pb) ProgressBar mAboutPb; - Handler handler = new Handler() { + private Handler handler = new MyHandler(this); + + static class MyHandler extends Handler { + + private WeakReference mWeakReference; + + public MyHandler(AboutActivity activity) { + mWeakReference = new WeakReference<>(activity); + } + @Override public void handleMessage(Message msg) { super.handleMessage(msg); - if (msg.what == 0) { - String version = (String) msg.obj; - mAboutVersion.setText("发现新版本 V" + version); - mAboutPb.setVisibility(View.GONE); - } else if (msg.what == 1) { - mAboutVersion.setText("已是最新版本"); - mAboutPb.setVisibility(View.GONE); + final AboutActivity activity = mWeakReference.get(); + if (activity != null) { + if (msg.what == 0) { + final String version = (String) msg.obj; + activity.mAboutVersion.setText("发现新版本 V" + version); + activity.mAboutPb.setVisibility(View.GONE); + } else if (msg.what == 1) { + activity.mAboutVersion.setText("已是最新版本"); + activity.mAboutPb.setVisibility(View.GONE); + } } } - }; + } @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java index f6489bb250..72941d049d 100644 --- a/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java +++ b/app/src/main/java/com/gh/gamecenter/SplashScreenActivity.java @@ -5,10 +5,8 @@ import android.app.ActionBar.LayoutParams; import android.content.*; import android.content.SharedPreferences.Editor; import android.os.Bundle; -import android.os.Handler; import android.support.v4.view.PagerAdapter; import android.support.v4.view.ViewPager; -import android.util.DisplayMetrics; import android.view.*; import android.widget.*; import com.gh.base.BaseActivity; @@ -46,8 +44,6 @@ public class SplashScreenActivity extends BaseActivity { private boolean isFirst; private boolean isNewFirstLaunch; - private Handler handler = new Handler(); - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -162,7 +158,7 @@ public class SplashScreenActivity extends BaseActivity { } long end = System.currentTimeMillis() - start; if (end < 3000) { - handler.postDelayed(new Runnable() { + getWindow().getDecorView().postDelayed(new Runnable() { @Override public void run() { launch(); @@ -263,12 +259,6 @@ public class SplashScreenActivity extends BaseActivity { finish(); } - @Override - protected void onDestroy() { - super.onDestroy(); - handler.removeCallbacksAndMessages(null); - } - private class GuidePagerAdapter extends PagerAdapter { private int[] pics = {R.drawable.splash_01}; @@ -280,18 +270,11 @@ public class SplashScreenActivity extends BaseActivity { @Override public Object instantiateItem(ViewGroup container, int position) { + View view = View.inflate(container.getContext(), R.layout.splash_guide_item, container); + ImageView ivImage = (ImageView) view.findViewById(R.id.splsh_guide_iv_image); + ivImage.setImageResource(pics[position]); if (position == pics.length - 1) { - View view = View.inflate(container.getContext(), R.layout.splash_guide_item, null); - - ImageView ivImage = (ImageView) view.findViewById(R.id.splsh_guide_iv_image); - ivImage.setImageResource(pics[position]); - TextView tvSkip = (TextView) view.findViewById(R.id.splsh_guide_tv_skip); - DisplayMetrics outMetrics = new DisplayMetrics(); - getWindowManager().getDefaultDisplay().getMetrics(outMetrics); - RelativeLayout.LayoutParams rparams = (RelativeLayout.LayoutParams) tvSkip.getLayoutParams(); - rparams.height = outMetrics.heightPixels / 4; - tvSkip.setLayoutParams(rparams); tvSkip.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -299,17 +282,8 @@ public class SplashScreenActivity extends BaseActivity { } }); - container.addView(view); - return view; - } else { - ImageView imageView = new ImageView(container.getContext()); - imageView.setScaleType(ImageView.ScaleType.FIT_XY); - imageView.setImageResource(pics[position]); - ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( - ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); - container.addView(imageView, params); - return imageView; } + return view; } @Override diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/RetrofitManager.java b/app/src/main/java/com/gh/gamecenter/retrofit/RetrofitManager.java index 64f2a50c90..2337aee000 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/RetrofitManager.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/RetrofitManager.java @@ -4,6 +4,7 @@ import com.gh.common.constant.Config; import com.gh.gamecenter.BuildConfig; import okhttp3.Cache; import okhttp3.OkHttpClient; +import okhttp3.OkHttpClient.Builder; import okhttp3.logging.HttpLoggingInterceptor; import okhttp3.logging.HttpLoggingInterceptor.Level; import retrofit2.Retrofit; @@ -19,31 +20,31 @@ import java.util.concurrent.TimeUnit; */ public class RetrofitManager { - private static RetrofitManager mInstance; - private ApiService apiService; - private DataService dataService; - private CommentService commentService; - private UserService userService; - private LibaoService libaoService; - private MessageService messageService; + private static RetrofitManager sInstance; + private ApiService mApiService; + private DataService mDataService; + private CommentService mCommentService; + private UserService mUserService; + private LibaoService mLibaoService; + private MessageService mMessageService; private RetrofitManager() { - Cache cache = new Cache(new File(OkHttpCache.getCachePath()), 10 * 1024 * 1024); // 10Mb - HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); + final Cache cache = new Cache(new File(OkHttpCache.getCachePath()), 10 * 1024 * 1024); // 10Mb + + final Builder builder = new OkHttpClient.Builder(); if (BuildConfig.DEBUG) { + HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(Level.BASIC); - } else { - interceptor.setLevel(Level.NONE); + builder.addNetworkInterceptor(interceptor); } - OkHttpClient okHttpClient = new OkHttpClient.Builder() + + final OkHttpClient okHttpClient = builder .addNetworkInterceptor(new OkHttpNetworkInterceptor()) - .addNetworkInterceptor(interceptor) .addInterceptor(new OkHttpInterceptor()) .connectTimeout(5, TimeUnit.SECONDS) .cache(cache) .build(); - - apiService = new Retrofit.Builder() + mApiService = new Retrofit.Builder() .client(okHttpClient) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) @@ -51,7 +52,7 @@ public class RetrofitManager { .build() .create(ApiService.class); - dataService = new Retrofit.Builder() + mDataService = new Retrofit.Builder() .client(okHttpClient) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) @@ -59,7 +60,7 @@ public class RetrofitManager { .build() .create(DataService.class); - commentService = new Retrofit.Builder() + mCommentService = new Retrofit.Builder() .client(okHttpClient) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) @@ -67,7 +68,7 @@ public class RetrofitManager { .build() .create(CommentService.class); - userService = new Retrofit.Builder() + mUserService = new Retrofit.Builder() .client(okHttpClient) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) @@ -75,7 +76,7 @@ public class RetrofitManager { .build() .create(UserService.class); - libaoService = new Retrofit.Builder() + mLibaoService = new Retrofit.Builder() .client(okHttpClient) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) @@ -83,7 +84,7 @@ public class RetrofitManager { .build() .create(LibaoService.class); - messageService = new Retrofit.Builder() + mMessageService = new Retrofit.Builder() .client(okHttpClient) .addConverterFactory(GsonConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) @@ -93,14 +94,14 @@ public class RetrofitManager { } public static RetrofitManager getInstance() { - if (mInstance == null) { + if (sInstance == null) { synchronized (RetrofitManager.class) { - if (mInstance == null) { - mInstance = new RetrofitManager(); + if (sInstance == null) { + sInstance = new RetrofitManager(); } } } - return mInstance; + return sInstance; } public static ApiService getApi() { @@ -128,27 +129,27 @@ public class RetrofitManager { } public ApiService getApiService() { - return apiService; + return mApiService; } public DataService getDataService() { - return dataService; + return mDataService; } public CommentService getCommentService() { - return commentService; + return mCommentService; } public UserService getUserService() { - return userService; + return mUserService; } public LibaoService getLibaoService() { - return libaoService; + return mLibaoService; } public MessageService getMessageService() { - return messageService; + return mMessageService; } } diff --git a/app/src/main/res/layout/splash_guide_item.xml b/app/src/main/res/layout/splash_guide_item.xml index 62d80fd04b..fe674d3fdf 100644 --- a/app/src/main/res/layout/splash_guide_item.xml +++ b/app/src/main/res/layout/splash_guide_item.xml @@ -1,7 +1,9 @@ - + + + app:layout_heightPercent = "25%" /> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index c7a4497d70..ae0ae314e7 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -12,6 +12,18 @@ --> + +