Skip to content

Commit

Permalink
调整Tips位置?
Browse files Browse the repository at this point in the history
  • Loading branch information
Fan095 committed Feb 7, 2024
1 parent 4965bce commit 64bf156
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.sevtinge.hyperceiler.prefs;

import android.content.Context;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.sevtinge.hyperceiler.ui.MainActivityContextHelper;

import fan.preference.Preference;

public class TipsPreference extends Preference {

MainActivityContextHelper mainActivityContextHelper;

public TipsPreference(@NonNull Context context) {
this(context, null);
}

public TipsPreference(@NonNull Context context, @Nullable AttributeSet attrs) {
this(context, attrs, 0);
}

public TipsPreference(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
setEnabled(false);
updateTips();
}

public void updateTips() {
mainActivityContextHelper = new MainActivityContextHelper(getContext());
String tip = mainActivityContextHelper.getRandomTip();
setSummary("Tips: " + tip);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ protected void hideActionBar() {
getAppCompatActionBar().hide();
}

public void setDisplayHomeAsUpEnabled(boolean isEnable) {
getAppCompatActionBar().setDisplayHomeAsUpEnabled(isEnable);
}

/*public void setActionBarEndView(View view) {
getAppCompatActionBar().setEndView(view);
}*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@
import java.util.List;

import fan.appcompat.app.AlertDialog;
import fan.external.view.weatherview.HolidayTheme;
import fan.external.view.weatherview.HolidayThemeHelper;

public abstract class BaseSettingsActivity extends BaseActivity {

private String initialFragmentName;
public Fragment mFragment;
public static List<BaseSettingsActivity> mActivityList = new ArrayList<>();

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -52,12 +53,17 @@ public void onCreate(Bundle savedInstanceState) {

protected void createUiFromIntent(Bundle savedInstanceState, Intent intent) {
mProxy.setupContentView();
mActivityList.add(this);
Fragment targetFragment = mProxy.getTargetFragment(this, initialFragmentName, savedInstanceState);
if (targetFragment != null) {
targetFragment.setArguments(mProxy.getArguments(intent));
setFragment(targetFragment);
}
HolidayThemeHelper.setup(this,
findViewById(R.id.weather_view),
findViewById(R.id.holiday_header),
HolidayTheme.THEME_AUTO,
getWindowManager().getDefaultDisplay().getRotation()
);
}

public void showRestartSystemDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,13 @@
import fan.preference.PreferenceFragment;
import fan.preference.internal.compat.PreferenceFragmentCompat;

public abstract class NavigationActivity extends BaseActivity implements PreferenceFragment.OnPreferenceStartFragmentCallback {
public abstract class NavigationActivity extends SettingsActivity implements PreferenceFragment.OnPreferenceStartFragmentCallback {

public abstract int getBottomTabMenu();

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_sub);
HolidayThemeHelper.setup(this,
findViewById(R.id.weather_view),
findViewById(R.id.holiday_header),
HolidayTheme.THEME_AUTO,
getWindowManager().getDefaultDisplay().getRotation()
);
setFragment(new TabNavigatorContentFragment());
/*setRestartView(view -> DialogHelper.showRestartDialog(this));*/
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import androidx.annotation.NonNull;

import com.sevtinge.hyperceiler.R;
import com.sevtinge.hyperceiler.ui.SubSettings;
import com.sevtinge.hyperceiler.ui.fragment.framework.OtherSettings;
import com.sevtinge.hyperceiler.ui.fragment.home.HomeDockSettings;
Expand All @@ -31,7 +32,6 @@
import com.sevtinge.hyperceiler.ui.fragment.various.AlertDialogSettings;

import fan.preference.Preference;
import fan.preference.internal.compat.PreferenceFragmentCompat;
import fan.preference.internal.compat.PreferenceFragmentCompat2;

public abstract class SettingsActivity extends BaseSettingsActivity implements fan.preference.PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,10 @@

public class BasePreferenceFragment extends PreferenceFragmentCompat {

private PreferenceManager mPreferenceManager;

@Override
public void onCreatePreferences(Bundle bundle, String s) {
mPreferenceManager = getPreferenceManager();
mPreferenceManager.setSharedPreferencesName(PrefsUtils.mPrefsName);
mPreferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE);
mPreferenceManager.setStorageDeviceProtected();
FragmentProxy mProxy = new FragmentProxy(this);
mProxy.onCreatePreferenceManager(getPreferenceManager());
}

public void setTitle(int titleResId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class FragmentProxy {
public FragmentProxy(Fragment fragment) {
}

public void onCreatePreferences(PreferenceManager preferenceManager) {
public void onCreatePreferenceManager(PreferenceManager preferenceManager) {
preferenceManager.setSharedPreferencesName(PrefsUtils.mPrefsName);
preferenceManager.setSharedPreferencesMode(Context.MODE_PRIVATE);
preferenceManager.setStorageDeviceProtected();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class NavigatorFragment extends PreferenceFragment {
@Override
public void onCreatePreferences(@Nullable Bundle bundle, @Nullable String s) {
FragmentProxy mProxy = new FragmentProxy(this);
mProxy.onCreatePreferences(getPreferenceManager());
mProxy.onCreatePreferenceManager(getPreferenceManager());
if (getContentResId() != 0) {
setPreferencesFromResource(getContentResId(), s);
initPrefs();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
Expand All @@ -22,11 +20,10 @@
import com.sevtinge.hyperceiler.R;
import com.sevtinge.hyperceiler.data.adapter.ModSearchAdapter;
import com.sevtinge.hyperceiler.data.adapter.NavigationPagerAdapter;
import com.sevtinge.hyperceiler.ui.MainActivityContextHelper;
import com.sevtinge.hyperceiler.ui.SubSettings;
import com.sevtinge.hyperceiler.ui.fragment.navigation.AboutPageFragment;
import com.sevtinge.hyperceiler.ui.fragment.navigation.HomePageFragment;
import com.sevtinge.hyperceiler.ui.fragment.navigation.SettingsPageFragment;
import com.sevtinge.hyperceiler.ui.fragment.base.navigation.AboutPageFragment;
import com.sevtinge.hyperceiler.ui.fragment.base.navigation.HomePageFragment;
import com.sevtinge.hyperceiler.ui.fragment.base.navigation.SettingsPageFragment;
import com.sevtinge.hyperceiler.utils.Helpers;
import com.sevtinge.hyperceiler.utils.SearchModeHelper;
import com.sevtinge.hyperceiler.utils.SettingLauncherHelper;
Expand Down Expand Up @@ -80,19 +77,6 @@ public void afterTextChanged(Editable s) {
AboutPageFragment mAboutPage = new AboutPageFragment();
NavigationPagerAdapter mNavigationPagerAdapter;
List<androidx.fragment.app.Fragment> mFragmentList = new ArrayList<>();
MainActivityContextHelper mainActivityContextHelper;
Handler mHandler = new Handler() {
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
if (msg.what == 0x11) {
updateSearchHint();//在这里写需要刷新完成的代码
removeMessages(0x11);
sendEmptyMessageDelayed(0x11, 10000);//这里想几秒刷新一次就写几秒*/
}
}
};


@Override
public void onCreate(Bundle bundle) {
Expand All @@ -115,8 +99,6 @@ public void onViewCreated(View view, Bundle bundle) {
super.onViewCreated(view, bundle);
initSearchView(view);
initNavigationView(view);
Message message = mHandler.obtainMessage(0x11);
mHandler.sendMessageDelayed(message, 3000);
}

private void initSearchView(View view) {
Expand All @@ -131,12 +113,6 @@ private void initSearchView(View view) {
mSearchAdapter.setOnItemClickListener(onSearchItemClickListener);
}

private void updateSearchHint() {
mainActivityContextHelper = new MainActivityContextHelper(requireContext());
String randomTip = mainActivityContextHelper.getRandomTip();
mSearchInputView.setHint("Tip: " + randomTip);
}

private void initNavigationView(View view) {
mFragmentPage = view.findViewById(R.id.frame_page);
mNavigationView = view.findViewById(R.id.navigation);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sevtinge.hyperceiler.ui.fragment.navigation;
package com.sevtinge.hyperceiler.ui.fragment.base.navigation;

import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.isMoreHyperOSVersion;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sevtinge.hyperceiler.ui.fragment.navigation;
package com.sevtinge.hyperceiler.ui.fragment.base.navigation;

import static com.sevtinge.hyperceiler.utils.api.VoyagerApisKt.isPad;
import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.getBaseOs;
Expand All @@ -7,6 +7,8 @@
import static com.sevtinge.hyperceiler.utils.devicesdk.SystemSDKKt.isMoreHyperOSVersion;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
Expand All @@ -22,6 +24,7 @@
import com.sevtinge.hyperceiler.R;
import com.sevtinge.hyperceiler.data.ModData;
import com.sevtinge.hyperceiler.data.adapter.ModSearchAdapter;
import com.sevtinge.hyperceiler.prefs.TipsPreference;
import com.sevtinge.hyperceiler.ui.MainActivityContextHelper;
import com.sevtinge.hyperceiler.ui.SubSettings;
import com.sevtinge.hyperceiler.ui.fragment.base.NavigatorFragment;
Expand All @@ -47,10 +50,23 @@ public class HomePageFragment extends NavigatorFragment {
Preference mAod;
Preference mGuardProvider;
Preference mMirror;
Preference mTip;
Preference mHeadtipWarn;

TipsPreference mTips;
MainActivityContextHelper mainActivityContextHelper;

Handler mHandler = new Handler() {
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
if (msg.what == 0x11) {
mTips.updateTips();//在这里写需要刷新完成的代码
removeMessages(0x11);
sendEmptyMessageDelayed(0x11, 6000);//这里想几秒刷新一次就写几秒*/
}
}
};

@Override
public int getContentResId() {
return R.xml.prefs_main;
Expand All @@ -60,6 +76,8 @@ public int getContentResId() {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().hide();
Message message = mHandler.obtainMessage(0x11);
mHandler.sendMessageDelayed(message, 6000);
}

@Override
Expand All @@ -71,8 +89,8 @@ public void initPrefs() {
mAod = findPreference("prefs_key_aod");
mGuardProvider = findPreference("prefs_key_guardprovider");
mMirror = findPreference("prefs_key_mirror");
mTip = findPreference("prefs_key_tip");
mHeadtipWarn = findPreference("prefs_key_headtip_warn");
mTips = findPreference("prefs_key_tips");

mPowerSetting.setVisible(!isAndroidVersion(30));
mMTB.setVisible(!isAndroidVersion(30));
Expand All @@ -96,8 +114,6 @@ public void initPrefs() {
}

mainActivityContextHelper = new MainActivityContextHelper(requireContext());
String randomTip = mainActivityContextHelper.getRandomTip();
mTip.setSummary("Tip: " + randomTip);

isOfficialRom();
if(!getIsOfficialRom()) isSignPass();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sevtinge.hyperceiler.ui.fragment.navigation;
package com.sevtinge.hyperceiler.ui.fragment.base.navigation;

import android.app.Activity;
import android.content.ComponentName;
Expand Down
10 changes: 4 additions & 6 deletions app/src/main/res/xml/prefs_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory>

<com.sevtinge.hyperceiler.prefs.TipsPreference
android:key="prefs_key_tips" />

<Preference
android:layout="@layout/headtip_warn"
android:key="prefs_key_headtip_warn"
Expand Down Expand Up @@ -373,11 +377,5 @@

</PreferenceCategory>

<Preference
android:enabled="false"
android:key="prefs_key_tip"
android:layout="@layout/preference_text"
android:summary="@string/tip_default" />

<Preference android:enabled="false" />
</PreferenceScreen>

0 comments on commit 64bf156

Please sign in to comment.