-
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor keybord view creation and reset
- Loading branch information
Showing
21 changed files
with
242 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
app/src/main/java/com/anysoftkeyboard/ime/AnySoftKeyboardPowerSaving.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.anysoftkeyboard.ime; | ||
|
||
import android.support.annotation.CallSuper; | ||
import android.support.annotation.NonNull; | ||
import android.view.View; | ||
|
||
import com.anysoftkeyboard.powersave.PowerSaving; | ||
import com.anysoftkeyboard.rx.GenericOnError; | ||
import com.anysoftkeyboard.theme.KeyboardTheme; | ||
import com.anysoftkeyboard.theme.KeyboardThemeFactory; | ||
|
||
public abstract class AnySoftKeyboardPowerSaving extends AnySoftKeyboardRxPrefs { | ||
|
||
private KeyboardTheme mCurrentKeyboardTheme; | ||
private boolean mPowerState; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
|
||
addDisposable(PowerSaving.observePowerSavingState(getApplicationContext(), 0).subscribe( | ||
powerState -> { | ||
mPowerState = powerState; | ||
setupInputViewWatermark(); | ||
}, | ||
GenericOnError.onError("Power-Saving icon") | ||
)); | ||
|
||
addDisposable(KeyboardThemeFactory.observeCurrentTheme(getApplicationContext()) | ||
.subscribe(this::onKeyboardThemeChanged, GenericOnError.onError("Failed to observeCurrentTheme"))); | ||
} | ||
|
||
@NonNull | ||
@Override | ||
protected String generateWatermark() { | ||
return super.generateWatermark() + (mPowerState ? "\uD83D\uDD0B" : ""); | ||
} | ||
|
||
@CallSuper | ||
protected void onKeyboardThemeChanged(@NonNull KeyboardTheme theme) { | ||
mCurrentKeyboardTheme = theme; | ||
|
||
final InputViewBinder inputView = getInputView(); | ||
if (inputView != null) { | ||
inputView.setKeyboardTheme(mCurrentKeyboardTheme); | ||
setCandidatesTheme(mCurrentKeyboardTheme); | ||
} | ||
} | ||
|
||
@Override | ||
protected void resetInputViews() { | ||
super.resetInputViews(); | ||
final InputViewBinder inputView = getInputView(); | ||
if (inputView != null) { | ||
inputView.setKeyboardTheme(mCurrentKeyboardTheme); | ||
setCandidatesTheme(mCurrentKeyboardTheme); | ||
} | ||
} | ||
|
||
protected abstract void setCandidatesTheme(KeyboardTheme theme); | ||
|
||
@Override | ||
public View onCreateInputView() { | ||
final View view = super.onCreateInputView(); | ||
getInputView().setKeyboardTheme(mCurrentKeyboardTheme); | ||
return view; | ||
} | ||
|
||
protected final KeyboardTheme getCurrentKeyboardTheme() { | ||
return mCurrentKeyboardTheme; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.