Skip to content

Commit

Permalink
Use Glide to load images / refactoring for image styles
Browse files Browse the repository at this point in the history
  • Loading branch information
chinalwb committed Apr 6, 2018
1 parent 83c18df commit 7d99fe7
Show file tree
Hide file tree
Showing 27 changed files with 988 additions and 665 deletions.
1 change: 1 addition & 0 deletions ARE/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion ARE/app/app.iml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes-jar" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-runtime-classes" />
Expand All @@ -110,26 +111,30 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/reports" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 26 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="com.android.support:support-media-compat-26.1.0" level="project" />
<orderEntry type="library" name="__local_aars__:/Users/wliu/Documents/Android/github/are/ARE/app/libs/tagsoup-1.2.1.jar:unspecified@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-compat-26.1.0" level="project" />
<orderEntry type="library" name="com.github.bumptech.glide:glide:4.3.1@jar" level="project" />
<orderEntry type="library" name="android.arch.lifecycle:common:1.0.0@jar" level="project" />
<orderEntry type="library" name="com.github.bumptech.glide:gifdecoder:4.3.1@jar" level="project" />
<orderEntry type="library" name="android.arch.core:common:1.0.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-fragment-26.1.0" level="project" />
<orderEntry type="library" name="com.android.support:support-vector-drawable-26.1.0" level="project" />
<orderEntry type="library" name="com.android.support:support-v4-26.1.0" level="project" />
<orderEntry type="library" name="android.arch.lifecycle:runtime-1.0.0" level="project" />
<orderEntry type="library" name="com.android.support:appcompat-v7-26.1.0" level="project" />
<orderEntry type="library" name="com.github.bumptech.glide:disklrucache:4.3.1@jar" level="project" />
<orderEntry type="library" name="com.android.support:animated-vector-drawable-26.1.0" level="project" />
<orderEntry type="library" name="com.android.support:support-annotations:26.1.0@jar" level="project" />
<orderEntry type="library" name="com.android.support:support-core-utils-26.1.0" level="project" />
<orderEntry type="library" name="com.android.support:support-core-ui-26.1.0" level="project" />
<orderEntry type="library" name="com.github.bumptech.glide:annotations:4.3.1@jar" level="project" />
<orderEntry type="module" module-name="emojipanel" />
<orderEntry type="module" module-name="colorpicker" />
<orderEntry type="module" module-name="glidesupport" />
</component>
</module>
3 changes: 2 additions & 1 deletion ARE/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
defaultConfig {
applicationId "com.chinalwb.are"
minSdkVersion 15
targetSdkVersion 21
targetSdkVersion 26
}

buildTypes {
Expand All @@ -21,4 +21,5 @@ dependencies {
compile files('libs/tagsoup-1.2.1.jar')
implementation project(':colorpicker')
compile project(path: ':emojipanel')
compile project(path: ':glidesupport')
}
1 change: 1 addition & 0 deletions ARE/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
Expand Down
83 changes: 14 additions & 69 deletions ARE/app/src/main/java/com/chinalwb/are/AREditText.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.chinalwb.are;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.support.v7.widget.AppCompatEditText;
import android.text.Editable;
import android.text.TextWatcher;
Expand All @@ -12,23 +11,21 @@
import android.text.style.QuoteSpan;
import android.text.style.StrikethroughSpan;
import android.text.style.StyleSpan;
import android.text.style.SubscriptSpan;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.chinalwb.are.spans.AreSubscriptSpan;
import com.chinalwb.are.spans.AreSuperscriptSpan;
import com.chinalwb.are.spans.AreUnderlineSpan;
import com.chinalwb.are.styles.ARE_FontSize;
import com.chinalwb.are.styles.ARE_Helper;
import com.chinalwb.are.styles.IARE_Style;
import com.chinalwb.are.styles.toolbar.ARE_Toolbar;

import java.util.List;

/**
* All Rights Reserved.
*
Expand All @@ -38,17 +35,6 @@
public class AREditText extends AppCompatEditText {

private static boolean LOG = false;

/**
* When the user 1st time presses DEL and the focus is at a start pos = 0
* Then mark this as true;
* When the user 2nd time presses DEL and the focus is at start pos = 0
* Then go to the previous edit text.
*
* Needs to reset it as false when user types other keys or user changes
* the edit text.
*/
private static boolean sToDetectDel = false;

private ARE_Toolbar sToolbar;

Expand All @@ -70,7 +56,6 @@ public AREditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mContext = context;
sToolbar = ARE_Toolbar.getInstance();
sToolbar.setEditText(this);
sStylesList = sToolbar.getStylesList();
init();
setupListener();
Expand All @@ -85,60 +70,15 @@ private void init() {
padding = Util.getPixelByDp(mContext, padding);
this.setPadding(padding, padding, padding, padding);
this.setTextSize(TypedValue.COMPLEX_UNIT_SP, Constants.DEFAULT_FONT_SIZE);
this.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
ARE_Toolbar.getInstance().setEditText(AREditText.this);
}
}
});
}

/**
* Sets up listeners for controls.
*/
private void setupListener() {
setupKeyListener();
setupTextWatcher();
} // #End of setupListener()

private void setupKeyListener() {
this.setOnKeyListener(new OnKeyListener() {

@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == Constants.KEY_DEL) {
int startPos = AREditText.this.getSelectionStart();
if (startPos == 0) {
if (sToDetectDel) {
focusToPrevious();
sToDetectDel = false;
return true;
}

sToDetectDel = true;
}
}
else {
sToDetectDel = false;
}
return false;
}
});
}

private void focusToPrevious() {
LinearLayout parentLayout = (LinearLayout) this.getParent();
int index = parentLayout.indexOfChild(this);
if (index > 0) {
int previousIndex = index - 1;
LinearLayout imageLayout = (LinearLayout) parentLayout.getChildAt(previousIndex);
AREditTextPlaceHolder placeHolderEdit = (AREditTextPlaceHolder) imageLayout.getChildAt(1);
placeHolderEdit.enforceFocus();
}
}

/**
* Monitoring text changes.
*/
Expand Down Expand Up @@ -177,7 +117,6 @@ public void afterTextChanged(Editable s) {
Util.log("User deletes: start == " + startPos + " endPos == " + endPos);
}

sToolbar.setEditText(AREditText.this);
for (IARE_Style style : sStylesList) {
style.applyStyle(s, startPos, endPos);
}
Expand All @@ -187,10 +126,6 @@ public void afterTextChanged(Editable s) {
this.addTextChangedListener(mTextWatcher);
}

public void removeTextWatcher() {
this.removeTextChangedListener(mTextWatcher);
}

/*
* ----------------------------------------- * Rich Text Style Area
* -----------------------------------------
Expand Down Expand Up @@ -330,4 +265,14 @@ public void onSelectionChanged(int selStart, int selEnd) {
ARE_Helper.updateCheckStatus(sToolbar.getBackgroundColoStyle(), backgroundColorExists);
ARE_Helper.updateCheckStatus(sToolbar.getQuoteStyle(), quoteExists);
} // #End of method:: onSelectionChanged

/**
* Needs this because of this bug in Android O:
* https://issuetracker.google.com/issues/67102093
*/
public void useSoftwareLayerOnAndroid8() {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O) {
this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
}
}
137 changes: 0 additions & 137 deletions ARE/app/src/main/java/com/chinalwb/are/AREditTextPlaceHolder.java

This file was deleted.

Loading

0 comments on commit 7d99fe7

Please sign in to comment.