Skip to content

Commit

Permalink
Fix theme init bugs and not work in Android P
Browse files Browse the repository at this point in the history
  • Loading branch information
lmovse committed Oct 7, 2018
1 parent 94158d2 commit ef0713e
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 38 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ dependencies {
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation files('libs/library-1.0.19.jar')
implementation 'com.getbase:floatingactionbutton:1.10.1'
implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha2'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:support-vector-drawable:28.0.0'
implementation 'com.android.volley:volley:1.1.1'
testImplementation 'junit:junit:4.12'
implementation 'com.jakewharton:butterknife:8.8.1'
implementation 'com.google.code.gson:gson:2.8.5'
Expand Down
Binary file removed app/libs/library-1.0.19.jar
Binary file not shown.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET"/>

<application
android:usesCleartextTraffic="true"
android:name=".common.MyApp"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
Expand Down Expand Up @@ -353,6 +352,7 @@ public void initTheme(int themeId, int colorPrimary) {
setTheme(R.style.AppTheme_Purple);
break;
default:
setTheme(R.style.AppTheme_Blue);
break;
}
}
Expand Down Expand Up @@ -420,9 +420,6 @@ public void onSourceChanged(int source) {
@Override
public void initView() {
mPresenter.initSettings();
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
initKitKatLayout();
}
mPresenter.loadData();
String original = getIntent().getStringExtra("original");
if (original != null) {
Expand All @@ -448,23 +445,4 @@ public void afterTextChanged(Editable s) {
});
}

@Override
public void initKitKatLayout() {
mStatus.setVisibility(View.VISIBLE);
CoordinatorLayout.LayoutParams params =
(CoordinatorLayout.LayoutParams) mAppBarLayout.getLayoutParams();

// 设置高度 将输入的整形数值转换为相对应的 dp 值
params.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 281,
this.getResources().getDisplayMetrics());
params.width = CoordinatorLayout.LayoutParams.MATCH_PARENT;
mAppBarLayout.setLayoutParams(params);

// 设置边距
params = (CoordinatorLayout.LayoutParams) mContentFrag.getLayoutParams();
params.setMargins(0, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 281,
this.getResources().getDisplayMetrics()), 0, 0);
mContentFrag.setLayoutParams(params);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ interface View extends BaseView{

void setMaterial(int colorPrimaryDark);

void initKitKatLayout();

void initTheme(int themeId, int colorPrimary);

void setAppTheme(int colorPrimary, int colorPrimaryDark);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public MainPresenter(SharedPreferences sharedPreferences, MainContract.View main
isNoteMode = mPref.getBoolean(AppPref.ARG_NOTE, false);
colorPrimary = mPref.getInt(AppPref.ARG_PRIMARY, Color.parseColor(SettingDefault.COLOR_PRIMARY));
colorPrimaryDark = mPref.getInt(AppPref.ARG_DARK, Color.parseColor(SettingDefault.COLOR_PRIMARY_DARK));
themeId = mPref.getInt(AppPref.ARG_THEME, 0);
themeId = mPref.getInt(AppPref.ARG_THEME, SettingDefault.THEME_ID);
transFrom = mPref.getInt(AppPref.ARG_FROM, SettingDefault.TRANS_FROM);
mResultLan = mPref.getString(AppPref.ARG_LAN, SettingDefault.RESULT_LAN);
isDoubleClick = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

public final class SettingDefault {

public static final int THEME_ID = ThemeColor.BLUE;

private SettingDefault() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ protected void request(String url, AppDataSource.TranslateCallback callback,
StringRequest request = new StringRequest(Request.Method.GET, url, s -> {
Gson gson = GsonInstance.newInstance();
T result = null;
System.out.println(s);
try {
result= gson.fromJson(s, translationClass);
result = gson.fromJson(s, translationClass);
} catch (Exception e) {
Log.e(TAG, "request: Gson parse error", e);
}
Expand All @@ -30,7 +31,10 @@ protected void request(String url, AppDataSource.TranslateCallback callback,
callback.onResponse(translate);
}
}
}, volleyError -> callback.onError(1));
}, volleyError -> {
Log.e(TAG, "request: request error", volleyError);
callback.onError(1);
});
MyApp.sRequestQueue.add(request);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package com.example.jooff.shuyi.fragment;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.jooff.shuyi.R;
import com.example.jooff.shuyi.activity.MainActivity;
import com.example.jooff.shuyi.constant.AppPref;
import com.example.jooff.shuyi.constant.ThemeColor;
import com.example.jooff.shuyi.activity.MainActivity;
import com.example.jooff.shuyi.util.AnimationUtil;

import java.util.Objects;
Expand All @@ -42,7 +43,8 @@ public class ThemeFragment extends DialogFragment {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
View view = Objects.requireNonNull(getActivity()).getLayoutInflater().inflate(R.layout.m_dialog_theme, null);
LayoutInflater layoutInflater = Objects.requireNonNull(getActivity()).getLayoutInflater();
@SuppressLint("InflateParams") View view = layoutInflater.inflate(R.layout.m_dialog_theme, null);
ButterKnife.bind(this, view);
mPreferences = getActivity().getSharedPreferences(AppPref.ARG_NAME, Context.MODE_PRIVATE);
isNightMode = mPreferences.getBoolean(AppPref.ARG_NIGHT, false);
Expand Down Expand Up @@ -117,12 +119,8 @@ public void setColor(Button color) {
mEditor.putInt(AppPref.ARG_DARK, ContextCompat.getColor(getContext(), colorPrimaryDark));
mEditor.putInt(AppPref.ARG_THEME, themeId);
mEditor.apply();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
startActivity(new Intent(getActivity(), MainActivity.class));
requireNonNull(getActivity()).overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
} else {
AnimationUtil.startActivity(requireNonNull(getActivity()), new Intent(getActivity(), MainActivity.class), color, colorPrimary, 618);
}
Intent intent = new Intent(getActivity(), MainActivity.class);
AnimationUtil.startActivity(requireNonNull(getActivity()), intent, color, colorPrimary, 618);
this.dismiss();
}

Expand Down

0 comments on commit ef0713e

Please sign in to comment.